2015-11-13 94 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 –

相關問題