request payload

formdata


这样的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("&");
}
}]);

本文详细介绍了在HTTP请求中设置header使后台能够正确获取post参数username和password的方法,通过将Content-Type设置为application/x-www-form-urlencoded并使用transformRequest进行参数转换。
392

被折叠的 条评论
为什么被折叠?



