Sphere
Log in Join
☆ 2

curl works but browser fetch gets CORS error — what is actually different?

I can POST to our internal API with curl and get a 200. The same request from fetch() in the browser fails with a CORS error before the server sees anything. I added Access-Control-Allow-Origin: * on the server and now it complains about a preflight. Why does curl not have this problem?

⚑ Report

4 replies

☆ 3
K Kevin ·2026-11-16#1

curl is not a browser, so it does not enforce the same-origin policy. The browser sends an OPTIONS preflight first because your request has a JSON content type and a custom header.

⚑ Report
☆ 0
R Rhea ·2026-11-18#2

I can see the OPTIONS request in the server log now. It gets a 404 from my router.

⚑ Report
☆ 0
A Amir ·2026-11-19#3

Handle OPTIONS before authentication and return the allowed methods and headers. Access-Control-Allow-Origin: * is also not enough if you send credentials; you need an explicit origin and Access-Control-Allow-Credentials: true.

⚑ Report
☆ 0
R Rhea ·6d ago#4

Added an OPTIONS route with the right headers and switched to an explicit origin. Fetch works now.

⚑ Report
Log in to reply.