我正在使用 cURL
在我的 PHP 服务器上通过 SOAP
将数据发布到 Dynamics CRM
。完成后,它以 HTTP 响应 header 的形式提供实体 GUID
。当试图通过我的 angular.factory 和 $http
访问它时。
我的 header 公开了,可以在 Chrome 开发者工具中查看,并为我提供了我需要的 GUID
。
获取promise数据的代码如下:
$http({
method: 'POST',
url: url,
data: formData,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).success(function (data, headers) {
var array = [];
array.data = data;
array.headers = headers('EntityId');
console.log(array.headers);
deferred.resolve(array);
})
return deferred.promise;
//etc
我得到的错误是:
headers is not a function()
但是,我可以使用以下方法访问某些 header 结果,例如状态 200 代码:
array.headers = headers;
但我需要访问我的自定义 header 。关于如何实现这一目标的任何想法?
最佳答案
根据关于 https://docs.angularjs.org/api/ng/service/$http 的弃用通知
The $http legacy promise methods success and error have been deprecated. Use the standard then method instead. If $httpProvider.useLegacyPromiseExtensions is set to false then these methods will throw $http/legacy error.
首选方式是:
$http.get('/someUrl')
.then(function(response){
var array = [];
array.data = response.data;
array.headers = response.headers('EntityId');
});
关于php - $http header 不是函数 - angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30845245/