Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将内容发布为应用程序/x-www-form-urlencoded angularjs$http.post拒绝使用我的内容类型_Angularjs_Api_Angularjs Http - Fatal编程技术网

如何将内容发布为应用程序/x-www-form-urlencoded angularjs$http.post拒绝使用我的内容类型

如何将内容发布为应用程序/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 = {

我正在与一家承包商合作——他们的团队正在制作服务器端API,而我正在使用angularjs组装一个javascript应用程序。他们坚持让api只允许使用
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'
    }
  });

});
有关详细信息,请参阅

这就够了,谢谢。我花了好几个小时寻找类似的东西。