Tengo una página web servida por FastAPI que al hacer clic en un botón inicia una solicitud POST usando Javascript puro a una ruta en mi API que luego debería redirigir a una página externa.
El JavaScript:
function submit(url) { let xhr = new XMLHttpRequest(); xhr.open("POST", url, false); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.send(); }En mi aplicación FastAPI, agregué lo siguiente:
app.add_middleware( CORSMiddleware, allow_credentials=True, allow_origins=['*', 'http://127.0.0.1:8080', 'http://127.0.0.1:8080/OpryW?', 'http://127.0.0.1:8080/OpryW'], allow_methods=["*"], allow_headers=["*"], )Sin embargo, al hacer clic en el botón, sigo recibiendo un error CORS.
Aquí hay algunos detalles sobre la solicitud:
PUBLICAR: http://127.0.0.1:8080/OpryW
Encabezados de solicitud:
POST /OpryW HTTP/1.1 Host: 127.0.0.1:8080 Connection: keep-alive Content-Length: 19 Pragma: no-cache Cache-Control: no-cache sec-ch-ua: "Chromium";v="94", "Google Chrome";v="94", ";Not A Brand";v="99" sec-ch-ua-mobile: ?0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36 sec-ch-ua-platform: "macOS" Content-Type: application/json Accept: */* Origin: http://127.0.0.1:8080 Sec-Fetch-Site: same-origin Sec-Fetch-Mode: cors Sec-Fetch-Dest: empty Referer: http://127.0.0.1:8080/OpryW? Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9Encabezados de respuesta:
HTTP/1.1 307 Temporary Redirect date: Mon, 01 Nov 2021 20:00:10 GMT server: uvicorn location: http://www.google.com access-control-allow-origin: * access-control-allow-credentials: true Transfer-Encoding: chunked¿Por qué sigo recibiendo un error CORS?
Gracias