Monday, April 30, 2012

LinkedIn API Requires Content-Type Request Header Set When Doing POST

I am not sure why LinkedIn API which does a HTTP POST request requires Content-Type for it to work. Otherwise, you will be receiving a 401 Unauthorized response which is kinda annoying. I suppose they can't support content-type inferencing or it is not feasible due to performance overhead or even security because they both support POST payload of XML and of JSON format.

So If you are POSTing for JSON, you need to make sure that you have the following HTTP Header,

Content-Type: application/json

If you have XML as a POST payload then use,

Content-Type: text/xml

If for whatever reason you have interchanged them, it will throw a bad request status code 400 and say that it cannot be parsed. Hope this will help someone as it had me scratching longer than I expected.
  • Related Links Widget for Blogspot

No comments: