更新: AWS API Gateway apiでCORSをセットアップしましたが、私はLambda Proxy設定を使用していますが、必要なヘッダをLambdaハンドラに入れる必要があります。レスポンス本文を受け取っているときにXMLHttpRequestを取得する
私はこれを理解することはできません。 CORSエラーが発生していますが、同時に、応答本体(実際の期待される応答)を取得しています。私はangular2/httpを使用しています。
XMLHttpRequestが https://xxxxxx.execute-api.us-east-2.amazonaws.com/dev/searchをロードすることはできません。いいえ 要求された リソースに 'Access-Control-Allow-Origin'ヘッダーが存在します。したがって、「http://localhost:4200」の原点は許可されません。
どのように考えても構いませんか?
コード(エラーは常にキャッチし、私はまだ適切な応答を取得しながら、プリントアウトされる):
public getNotes(searchString: string, authtoken: string): Observable<NotesResponse> {
let headers = new Headers({'Content-Type': 'application/json'});
headers.append('Authorization', authtoken);
headers.append('search-key', searchString);
let options = new RequestOptions({headers: headers});
return this.http.post(this.notesUrl, null, options) // ...using post request
.map((res:Response) => res.json()) // ...and calling .json() on the response to return data
.catch((error:any) => Observable.throw(error.json().error || 'Server error')); //...errors if
}
this.com.notesService.getNotes(this.com.searchQuery, result).subscribe(
notes => {
console.log("Notes: notes");
},
err => {
// Log errors if any
console.log("There was an error retrieving the notes: " + err);
});
http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource/42744707#42744707 – sideshowbarker
これは私の質問には答えませんまったく。私は実際の応答jsonを取得していますが、同時に私はCORSの例外を取得します。それが単にCORSの問題だったなら、私はそのリソースに関する投稿をすることができません。 – Vladimir