2015-11-13 51 views
1

我试图通过JavaScript访问Adobe TypeKit API,使用AngularJS。 使用$http.get(https://typekit.com/api/v1/json/kits?token=myToken)失败的身份验证请求,并出现错误: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

如果我使用$http.jsonp(...)未验证请求是succesfull,这可能是由于Adobe的CORS政策,但随着typekit文档中所述

For security reasons, authenticated API requests are currently unavailable with callbacks.

因此,使用jsonp,我无法访问API提供的许多端点。 我不明白的是,如果我使用邮递员或者使用chrome本身来执行它,那么同样确切的请求将会失败。我tryied设置请求标题完全一样在邮递员,但没有奏效。尝试了各种各样的标题设置,但没有改变。 有什么想法?

回答

0

您可以禁用chrome网络安全,然后试试看。要禁用网络安全,请打开您的终端并输入以下内容/ Applications/Google \ Chrome.app/Contents/MacOS/Google \ Chrome --disable- web-security -allow-file-access-from-files --allow-file-access --user-data-dir =〜/ chrome-test/spec/runner.html

+0

我不知道为什么,我不知道如何,但它的工作原理,但我需要设置一个标题:'{'X-Requested-With':'XMLHttpRequest'}' –

+0

这是什么意思?以及如何在没有网络安全的情况下运行chrome而复制此内容? –

+0

当网络安全被禁用时它工作正常吗?请参阅此问题以获取更多详细信息http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the -requested-resource –

相关问题