私は以下の問題があります。 私のAngular 4 Appでは、公開APIから(GET Request)データを取得したいと考えています。CORSの問題を角度で解決する(APIへのアクセスなし)?
XMLHttpRequest cannot load https://api.kraken.com/0/public/AssetPairs . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:4200' is therefore not allowed access.
私はそのための解決策を見つけましたが、それらのどれもとして私の問題を解決していない:ちょうどブラウザからまたは郵便配達が完璧に動作しますが、私はHTTPの角度からの要求をプレゼントするとき、私はそのエラーを取得経由でURLを呼び出し
アドバイスを事前に
let headers = new Headers({ 'Access-Control-Allow-Origin': 'true' , 'Content-Type':'application/json', 'crossDomain':'true'});
let options = new RequestOptions({ headers: headers, withCredentials: false});
return this.http.get('https://api.kraken.com/0/public/AssetPairs' , options)
.map(
(response: Response) => {
console.log(response);
const markets = response.json();
return markets;
},
(error: Error) => {
console.log('error');
console.log(error);
}
);
感謝を:それは私もヘッダを設定しようとしたが、それはうまくいきませんでした...私の制御下 サードパーティのAPIではありません!
CORSはサーバーリソースを保護します。クライアントはそれをバイパスできません –
@JaromandaX実際には、webpackのプロキシを使ってCORSをバイパスできます。 – Baruch
私が言ったように**クライアント**はCORSをバイパスできません –