0
httpリクエストを送信しようとしたとき、CORSについてこのエラーが発生しました。Angular2アプリからhttp投稿リクエストを送信する際にCORSを有効にする方法
XMLHttpRequest cannot load 'sever-domain'.
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'my-firebsase-hosted-app-domain' is therefore not allowed access.
次に、このようなヘッダーをhttpリクエストに設定します。
let headers = new Headers(
{
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/x-www-form-urlencoded'
}
);
let options = new RequestOptions({ headers: headers });
this.postRequestSub = this._http.post(this.url, body, options);
私はまだ同じエラーがありますが、これを解決する正しい方法ではありませんか?
CORSをサーバー上で構成する必要があります。角はそれに関与していません。 –
プロキシを使用してクライアント側で処理できます。 https://webpack.github.io/docs/webpack-dev-server.html#proxy –
すぐにお返事ありがとうございます。あなたは正しく、このようなプロキシを設定することで、このエラーを処理することができますか? [リンク](http://stackoverflow.com/questions/37172928/angular-cli-server-how-to-proxy-api-requests-to-another-server) – taku845