2

I have read about AngularJS post request header which is application/json

But I want to change it to:

Content-Type=application/x-www-form-urlencoded; charset=UTF-8

I do the following but the post request is still sent with the same application/json

Here is the Angular:

 $http.post("server.php", checkUserPostData, 
{"headers" : "Content-Type=application/x-www-form-urlencoded; charset=UTF-8"})

            .success(function(data, status, header, config){
                if(data=='exists')
                return true;
                else return false;
            });

How should I set the config header of the request then?

Jonatas CD
  • 878
  • 2
  • 10
  • 19
Mostafa Talebi
  • 8,825
  • 16
  • 61
  • 105
  • possible duplicate of [AngularJS - Any way for $http.post to send request parameters instead of JSON?](http://stackoverflow.com/questions/12190166/angularjs-any-way-for-http-post-to-send-request-parameters-instead-of-json) – Jim G. Jan 27 '15 at 21:27

1 Answers1

4

The headers need to be a JSON object.

Try:

{"headers" : { "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8" }}

From here: https://docs.angularjs.org/api/ng/service/$http

headers – {Object} – Map of strings or functions which return strings representing HTTP headers to send to the server. If the return value of a function is null, the header will not be sent.

Douglas Adams
  • 1,550
  • 1
  • 11
  • 7