2014-05-24 33 views
2

我看了一下AngularJS POST请求头是application/json

但我想将其更改为:

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

我做以下,但POST请求仍然使用相同的application/json

送到这里是角:

$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; 
      }); 

我应该如何设置请求的配置标题呢?

+0

可能重复[AngularJS - 任何方式为$ http.post发送请求参数,而不是JSON?](http://stackoverflow.com/questions/12190166/angularjs-any-way-for-http-后到发送请求参数,INSTEAD-OF-JSON) –

回答

4

标题需要是JSON对象。

尝试:

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

从这里: https://docs.angularjs.org/api/ng/service/$http

头 - {}对象 - 地图,返回表示HTTP标头发送到服务器字符串字符串或功能。如果函数的返回值为空,则不会发送标题。