角度http请求的CORS问题

时间:2014-12-22 06:35:20

标签: angularjs node.js

我正在尝试从口袋API调用访问结果,这需要发布到他们的域。但是,当我发帖时,我得到了问题

XMLHttpRequest cannot load https://getpocket.com/v3/get. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:3000' is therefore not allowed access. The response had HTTP status code 406.

但是,我已将httpProvider选项配置为此类。

$httpProvider.defaults.useXDomain = true;
$httpProvider.defaults.withCredentials = true;
delete $httpProvider.defaults.headers.common["X-Requested-With"];
$httpProvider.defaults.headers.common["Accept"] = "application/json";
$httpProvider.defaults.headers.common["Content-Type"] = "application/json";

我认为配置会允许请求继续进行,但他们没有。我需要一个帖子请求,所以jsonp将不起作用。任何想法将不胜感激!

1 个答案:

答案 0 :(得分:2)

尝试添加此行

$httpProvider.defaults.useXDomain = true;