request payload => formdata

request payload


request payload => formdata_第1张图片
 

 

formdata


request payload => formdata_第2张图片
 

 


request payload => formdata_第3张图片
这样的post提交,默认是request payload

后台无法取得post的参数username, password

 

解决方案是设置 http request的 header

设置 Content-Type 为application/x-www-form-urlencoded

app.config(['$httpProvider',
    function($httpProvider){
        $httpProvider.defaults.headers.post = {'Content-Type':'application/x-www-form-urlencoded'};
        $httpProvider.defaults.transformRequest = function(obj){
            var str = [];
            for(var p in obj)
                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
            return str.join("&");
        }
    }]);

 
request payload => formdata_第4张图片
 

 

你可能感兴趣的:(JavaScript,Angular)