Friday, April 18, 2014

Http Accept - 406

There are many HTTP headers which go unnoticed. Accept is one such header.

Accept is a way to tell the server what the client accepts. A server can smartly handle this.

e.g. Accept: application/xml to a service returns xml and Accept: application/json to same end point should return json.

Sometimes we have the server side code as to strictly say we support requests with Accept: application/json. I have seen ROR doing it when the return is of type JSON.

If the Web server detects that the data it wants to return is not acceptable to the client, it returns a header containing the 406 error code. 

I have observed the below behavior with our ROR set up


Accept: application/xml,application/json
Accept: application/json,application/xml"
Accept: application/xml;q=0.9,application/json
Accept: */*

Failure (406)

Accept: */*, application/xml;
Accept: application/xml,*/*;
Accept: application/xml;q=0.9,*/*;
Accept: application/xml;

Note: I see */* is successful if Accept has only one entry with */*, else it expects application/json somewhere.

Chrome browser by default sends (may depend on browser and version)

  1. Accept:

So again it will fail. There are browser add ons which can help manipulate any of the HTTP headers for calls made through the browser. I have to use that for this call.

HTH someone, someday