LoginSignup
1
0

More than 3 years have passed since last update.

AWSのAPIGatewayのAPIをXMLHttpRequestでリクエストしたらCORS policyエラーが出てしまう場合

Posted at

問題

APIGatewayのCORSでの設定は「Access-Control-Allow-Origin: *」としているのに
下記エラーが発生してAPIのレスポンスがうまく取得できない
Access to XMLHttpRequest at 'https://xxx' from origin 'https://xxx' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

治し方

CORSの設定だけではなく、ajaxの設定等が間違えていないか確認する。
私の場合は「Content-Type」をデフォルトにしていたところを「application/json」にしたところ治りました。

参考サイト

どうやらCORSの設定ではなく、APIゲートウェイへのアクセス失敗でも発生するエラーのようです。詳しくは下記Qiita記事へ。この記事に助けていただきました。

API GatewayでのCORS有効化の注意点

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0