当該エラー
Access to XMLHttpRequest at 'https://server-hoge' from origin 'https://client-hoge' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
サーバー側(FastAPIの場合)
公式ドキュメントなどを元にCORSの許可を設定
app = FastAPI()
origins = [
"https://client-hoge",
"http://localhost",
"http://localhost:8080",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
クライアント側(Flutterの場合)
'Access-Control-Allow-Origin': '*'
をヘッダに追加
headers: <String, String>{
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
CORSについて
CORSについてはこの方が詳しく書いているのでそちらを是非
https://qiita.com/att55/items/2154a8aad8bf1409db2b