0

I am learning how to work with XMLHttpRequests. I know that request.setRequestHeader() is an important factor. I just don't understand why. It took me a while but I have at least found a list of Headers here and here, but I still don't understand what each one of them does, and what value goes with each. Is there a resource that gives an example and explains what they are for?

1 Answer 1

1

A quick search found: http://code.tutsplus.com/tutorials/http-headers-for-dummies--net-8039

(no offense from the title; it looked like a pretty thorough article) Skip down to "HTTP Headers in HTTP Requests"

Just eyeballing the list, the most important headers are for "content negotiation":

  • Content-Type Most servers will need this to parse & route your request to the right function:

Content-Type: application/json

  • Accept Tells the server what it can send back

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8

  • Authorization In my work, I usually have to provide an authorization key. But the server will tell you whether you need this or not.

Authorization: Bearer aasdadadadadadsasd

The other ones are either optional, or get added by the browser. You can open the dev console in your browser and look at the network messages going back and forth & do a search on individual headers to see what they mean.

Not the answer you're looking for? Browse other questions tagged or ask your own question.