[英]Custom HTTP headers always get added under “Access-Control-Request-Headers”
I am new to Angular JS. 我是Angular JS的新手。 I am writing a simple client to pull data from a HTTP endpoint.
我正在编写一个简单的客户端来从HTTP端点提取数据。
All headers I set are sent over the wire under the header Access-Control-Request-Headers
, but not as actual HTTP headers in the request. 我设置的所有标头都通过标题
Access-Control-Request-Headers
,但不是请求中的实际HTTP标头。
delete $http.defaults.headers.common['X-Requested-With'];
var config = {
headers: {
'customHeader1': 'value1'
}
};
$http.defaults.headers.get = {
'customHeader2': 'value2'
};
$http.get("http://localhost:8280/abc",config).success(function(data) {
// alert(data);
$scope.names = data.records;
}).error(function(response, data, status, header) {
alert(status);
});
Could you try that suggestion from the official Angular JS documentation : 你能从官方的Angular JS文档中尝试这个建议吗:
To explicitly remove a header automatically added via $httpProvider.defaults.headers
on a per request basis, Use the headers property, setting the desired header to undefined. 要基于每个请求显式删除通过
$httpProvider.defaults.headers
自动添加的标头,请使用headers属性,将所需标头设置为undefined。 For example: 例如:
var req = {
method: 'POST',
url: 'http://example.com',
headers: {
'Content-Type': undefined
},
data: { test: 'test' }
}
$http(req).then(function(){...}, function(){...});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.