I am trying to make a POST request for cross origin using Angular $ http with the following code.
//I've tried setting and removing these http config options $http.defaults.useXDomain = true; delete $http.defaults.headers.common['X-Requested-With']; $http.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded'; //Basic request, with some private headers removed return $http({ method: 'POST', //withCredentials:true, headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}, params: params, url: url });
The OPTIONS preset request receives 200 OK , but the subsequent POST receives a 400 Bad Request response. If I look at the trace in the Chrome debugging window, I donβt see the Content-Type: application/x-www-form-urlencoded; charset=UTF-8 header Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Content-Type: application/x-www-form-urlencoded; charset=UTF-8 for POST. I assume that is why the server returns a Bad Request response.
I set some other custom headers that I skipped from the above code, and they are sent and displayed well.
It should also be mentioned that I can make this request using the Advanced Rest Client application for Chrome and get the correct answer. (Access token)
I also tried just executing XMLHttpRequest (), but I am getting the same errors.
Any insight into why my Content-Type header is not set?
user3783608
source share