HomeGuidesHow to Debug and Fix CORS Errors with cURL and Browser DevTools
API & Security6 min readUpdated 2026-11-06

How to Debug and Fix CORS Errors with cURL and Browser DevTools

Demystify Access-Control-Allow-Origin, preflight OPTIONS requests, and troubleshoot Cross-Origin Resource Sharing in minutes.

Need to do this immediately?

Use our free, private client-side browser tool with zero installation.

Launch cURL to Fetch Converter
"No 'Access-Control-Allow-Origin' header is present on the requested resource." Every web developer has encountered this dreaded console error. Understanding how browsers enforce Cross-Origin Resource Sharing (CORS) is essential for modern full-stack development.

CORS is a Browser Security Mechanism, Not a Server Bug

The first principle to understand is that CORS is enforced strictly by the web browser to protect users from malicious scripts on one origin making unauthorized requests to another authenticated origin.

Your API server usually handles the request and returns data successfully, but the browser blocks JavaScript code from reading the response because the server response headers did not explicitly permit the calling domain.

Pro Tip:Never set `Access-Control-Allow-Origin: *` together with `Access-Control-Allow-Credentials: true`; browsers explicitly reject this unsafe wildcard configuration.

Simulating Preflight OPTIONS Requests with cURL

For requests with custom headers (e.g. `Authorization: Bearer <token>`) or content types like `application/json`, browsers send a preflight HTTP `OPTIONS` request before the actual `POST` or `GET`.

If the server fails to respond to `OPTIONS` with `200 OK` or `204 No Content` and the proper `Access-Control-Allow-Methods` headers, the browser immediately cancels the main request.

Step-by-Step Tutorial

1

Send Preflight OPTIONS Request with cURL

Run `curl -i -X OPTIONS https://api.example.com/v1/data -H "Origin: https://myapp.com" -H "Access-Control-Request-Method: POST"`.

2

Verify Access-Control Headers

Check that the response headers contain `Access-Control-Allow-Origin: https://myapp.com` and `Access-Control-Allow-Headers: Authorization, Content-Type`.

3

Configure Server-Side CORS Middleware

Enable CORS middleware in Express, Fastify, or your API gateway to automatically handle OPTIONS preflight routes with status 204.

Ready to Try It Yourself?

DocSwift processes everything directly on your device. Fast, safe, and completely free forever.

How helpful was this guide?

Rated 4.9 / 5 by 3,420+ users worldwide

Share with Colleagues & Friends

Help others protect their document privacy

Frequently Asked Questions

Why does my API work in Postman or cURL but fail in the browser?

Postman and cURL are terminal HTTP clients, not web browsers. They do not enforce the browser Same-Origin Policy (SOP) or CORS restrictions.

Can I fix CORS issues by modifying client-side JavaScript?

No. CORS headers must be sent by the destination server or an intermediate reverse proxy (like Cloudflare, NGINX, or Next.js API rewrite routes).