の「アクセス制御 - 許可 - 起源」ヘッダーを追加:私は次のエラーを取得するオーレリアのフロントエンドを経由して私のAPIにアクセスしようとするとアウレリア
XMLHttpRequest cannot load https://[my aws API URL here]/auth. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://localhost:9000 ' is therefore not allowed access. The response had HTTP status code 403
これは私のコードです:
constructor(Aurelia, HttpClient) {
HttpClient.configure(http => {
http.withBaseUrl(config.baseUrl);
});
this.http = HttpClient;
this.app = Aurelia;
this.session = JSON.parse(localStorage[config.tokenName] || null);
}
login(username, password) {
var client = new HttpClient();
client.createRequest(config.apiUrl + '/auth', { username, password })
.asPost()
.withHeader('Access-Control-Allow-Origin', '*')
.withBaseUrl(config.baseUrl)
.send()
.then((response) => response.content)
.then((session) => {
localStorage[config.tokenName] = JSON.stringify(session);
this.session = session;
this.app.setRoot('app');
});
}
私は間違っていますか?
郵便配達員でうまくいきます。
'Access-Control-Allow-Origin'は_response_ヘッダで、データを要求しようとしているサーバが送信しなければなりません。 – CBroe
したがって、私のAPI(AWS APIゲートウェイ)は、要求がPostmanアプリケーションから来たときにこのヘッダーを送信しますが、ローカル開発サーバー(localhost:9000)から要求が来たときは送信しないとします。私はすべてこれで非常に新しいと思います。 ;) –
ブラウザの開発者ツールで特定の要求のネットワークログを調べることで、それを判断できます。 –