更改angular $http post 默认json

来源:互联网 发布:色系shipin软件下载 编辑:程序博客网 时间:2024/06/05 07:47

By default, the $http service will transform the outgoing request by serializing the data as JSON and then posting it with the content- type, "application/json". When we want to post the value as a FORM post, we need to change the serialization algorithm and post the data with the content-type, "application/x-www-form-urlencoded".

Example from here.

$http({    method: 'POST',    url: url,    headers: {'Content-Type': 'application/x-www-form-urlencoded'},    transformRequest: function(obj) {        var str = [];        for(var p in obj)        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));        return str.join("&");    },    data: {username: $scope.userName, password: $scope.password}}).success(function () {});
0 0
原创粉丝点击