$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 :

enter image description here


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 :

enter image description here

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.

enter image description here


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 :

enter image description here

questions :

  1. is necessary add requestheader append content-type "application/json" in apache configuration? if add 415 errors on post requests.
  2. what problem angularjs , restangular won't append content-type headers network calls on get?
  3. 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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -