Skip to content

Instantly share code, notes, and snippets.

@sourcec0de
Created December 11, 2012 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sourcec0de/4256505 to your computer and use it in GitHub Desktop.
Save sourcec0de/4256505 to your computer and use it in GitHub Desktop.
Nutritionix Response Headers
[
{
"HEADERS": {
"date": "Tue, 11 Dec 2012 06:55:37 GMT",
"server": "Apache/2.2.22 (Amazon)",
"x-powered-by": "PHP/5.3.15",
"content-length": "1486",
"connection": "close",
"content-type": "text/html; charset=UTF-8"
}
},
{
"REQUEST_PARAMS": {
"protocol": "http",
"host": "devapi.nutritionix.com",
"pathname": "/v1/api/item/",
"query": {
"query": "cheese",
"appKey": "MY_SECRE_APP_KEY",
"appId": "4937ead8"
},
"port": "80",
"method": "GET"
}
}
]

#How Current Header(Content-Type)

{"content-type":"text/html; charset=UTF-8"}

Render JSON With this content type

{"content-type":"application/json; charset=UTF-8"}

#Why This can cause incompatibility with some browsers, and even break some server side code that is configured to parse a JSON response and in turn the Response Headers tell it that it is HTML.

  • Also, ensure that you response not just to JSON requests, but html requests and render as JSON. Firefox XHR requests come in as HTML but expect JSON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment