我对网络开发很陌生,所以我需要帮助。 我想向Web服务器发送HTTP请求以获取一些数据。要授权用户,我必须在用户代理标头中发送一个秘密。
$http({
method: 'GET',
url: 'https://my-website/some_data',
headers: {
'Accept': 'application/json;charset=UTF-8',
'User-Agent': 'service/2.0 (Android 4.3) sec=secret_key'
}
}).success(function(data){
$scope.locations = data;
}).error(function(data, status, headers, config) {
alert("error");
});
问题是Chrome始终打印:
Refused to set unsafe header "User-Agent"
和
XMLHttpRequest cannot load
https://my-website/some_data. No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://127.XXXXX' is therefore not allowed
access. The response had HTTP status code 403.
出了什么问题?