$http header 'Content-Type' not appending in the header - AngularJS -
i'm using $http
request , wanted append 'content-type': 'application/json'
in header. if don't append header 415 (unsupported media type)
error thrown.
i'm using apache 2.2.13 proxypass, in i not requestheader append content-type "application/json"
. if put requestheader
configuration in apache $http.get
works fine , 'content-type'
appended.
scenario 1 : using $http
, trying request
request :
$http({ method: 'get', headers: { 'content-type': 'application/json'}, url: '/items/?customerid=5656' });
chrome network tab :
scenario 2 : using restangular
, trying same request
request :
restangular.setdefaultheaders({'content-type': 'application/json'}) restangular.setbaseurl('/items') restangular.all('').getlist({customerid: '103020'}, {'content-type': 'application/json'});
chrome network tab :
the other interesting part here is, when mistakes on request header like,
restangular.setdefaultheaders({'contentttt-type': 'application/json'})
, try scenario 1, notice following in chrome network tab.
scenario 3 : using jquery
ajax, trying same request
request :
$.ajax({ url: "/items/?customerid=103020", type: "get", beforesend: function(xhr){xhr.setrequestheader('content-type', 'application/json');}, success: function() { alert('success!'); } });
chrome network tab :
questions :
- is necessary add
requestheader append content-type "application/json"
in apache configuration? if add 415 errors onpost
requests. - what problem angularjs , restangular won't append
content-type
headers network calls onget
? - what best solution solve this? have tried out combinations no luck!
versions :
angular : 1.2.22
restangular : 1.4.0
setting content-type header field on http request doesn't have request body (such get) non-sense.
maybe really want set "accept"?
Comments
Post a Comment