如何将内容发布为应用程序/x-www-form-urlencoded angularjs$http.post拒绝使用我的内容类型
我正在与一家承包商合作——他们的团队正在制作服务器端API,而我正在使用angularjs组装一个javascript应用程序。他们坚持让api只允许使用如何将内容发布为应用程序/x-www-form-urlencoded angularjs$http.post拒绝使用我的内容类型,angularjs,api,angularjs-http,Angularjs,Api,Angularjs Http,我正在与一家承包商合作——他们的团队正在制作服务器端API,而我正在使用angularjs组装一个javascript应用程序。他们坚持让api只允许使用application/x-www-form-urlencoded调用,因此我试图找出如何使用$http进行urlencoded调用,并遇到了一些问题。我发现的所有说明页面似乎都集中在angularjs的旧版本上 我尝试使用以下代码: $scope.makeApiCall = function( ){ var apiData = {
application/x-www-form-urlencoded
调用,因此我试图找出如何使用$http进行urlencoded调用,并遇到了一些问题。我发现的所有说明页面似乎都集中在angularjs的旧版本上
我尝试使用以下代码:
$scope.makeApiCall = function( ){
var apiData = {
"key1" : "value1",
"key2" : "value2"
};
var apiConfig = {
"headers" : {
"Content-Type" : "application/x-www-form-urlencoded;charset=utf-8;"
}
};
return $http.post('/Plugins/apiCall', apiData, apiConfig)
.then(function(response){
$scope.data=response.data;
});
};
但是当我调用时,开发人员工具报告它使用Content-Type:text/html,而不是使用我提供的内容类型;字符集=utf-8
如何让我的$http.post
发送正确的内容类型?如何将内容发布为应用程序/x-www-form-urlencoded
使用$httpParamSerializerJQLike
服务转换数据:
.controller(function($http, $httpParamSerializerJQLike) {
//...
$http({
url: myUrl,
method: 'POST',
data: $httpParamSerializerJQLike(myData),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
});
有关详细信息,请参阅