我有一个角度应用程序,我正在用测试键提出一个http请求。
var authString = ('Basic '+ btoa("ef7d25e3-0771-46ba-b4f8-bc9ac719777a:"));
var url = 'https://api.postmates.com/v1/customers/cus_KHKFAOoa9PWhPF/delivery_quotes';
var headers = {'Content-Type': 'application/x-www-form-urlencoded', 'Authorization':authString};
var req1 = { method: 'POST',
url: url,
headers:headers,
data: params1,
};
return $http(req1);
响应是:'No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access. The response had HTTP status code 401.'
我有同样的代码在python中处理请求,但我不知道为什么我不能让它在我的角度应用程序中工作。
我确实设置了默认的http头:
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];我认为认证是错误的
发布于 2015-09-01 16:47:31
出于安全原因,我们目前不允许访问控制标头。如果直接从客户端执行API调用,那么很可能会公开API凭据。
我建议使用Python,或者从我们的社区成员中查看这个Node包:https://github.com/lambtron/postmates-node
如果你还有什么问题请告诉我!
https://stackoverflow.com/questions/32278282
复制相似问题