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?

closed as off-topic by amon, user40980, gnat, Bart van Ingen Schenau, World Engineer Mar 17 '14 at 14:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to recommend a tool, library or favorite off-site resource are off-topic for Programmers as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – amon, gnat, Bart van Ingen Schenau, World Engineer
If this question can be reworded to fit the rules in the help center, please edit the question.

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.