StackShelf
HTTPエラー エラー解決

CORS policy: The request client is not a secure context の原因と解決法

CORS policy: The request client is not a secure context の原因と具体的な解決手順をまとめました。

1分で読める
httpHTTPエラーCORS policyCORSCORS policy: The request client is not a

エラーメッセージ(全文)

CORS policy: The request client is not a secure context

このエラーとは

CORS policy: The request client is not a secure context は HTTP 開発でよく遭遇するエラーです。

想定環境: Windows / macOS / Linux

よく出る状況: ブラウザ fetch / axios 時

よくある原因

  • サーバー側 CORS 未設定
  • preflight OPTIONS 未対応
  • credentials 設定不一致

解決方法

方法1: サーバーで CORS ヘッダ

Access-Control-Allow-Origin を設定.

それでも直らないとき

バージョン情報(HTTP のバージョン、OS、実行コマンド)を添えて、エラーメッセージ全文と直前に変更した点を確認してください。ログの数行上にも原因の手がかりが残っていることが多いです。

まとめ

「CORS policy: The request client is not a secure context」は サーバー側 CORS 未設定 が原因のことが多いです。上記の手順で切り分けてください。

次にやること

同じ HTTP カテゴリの関連エラーもあわせて確認してください。

よくある質問

CORS policy: The request client is not a secure context とは何ですか?

CORS policy: The request client is not a secure context は HTTP 実行時に表示されるエラーです。サーバー側 CORS 未設定

CORS policy: The request client is not a secure context の原因は?

サーバー側 CORS 未設定。preflight OPTIONS 未対応。credentials 設定不一致。

CORS policy: The request client is not a secure context の直し方は?

サーバーで CORS ヘッダ:Access-Control-Allow-Origin を設定.

HTTP で CORS policy が出るのはなぜ?

ブラウザ fetch / axios 時

CORS policy: The request client is not a secure context を防ぐには?

次に読むべき記事

同カテゴリ「HTTPエラー」の記事

学習ルート

体系的に学びたい方はこちらから。

エラー・トラブル集で続きを探す →

あわせて読みたい