GUIDE深度 · Deep dive

cURL to fetch/axios Pitfalls

Conversion is not literal: browser fetch is subject to CORS, Node fetch does not carry browser cookies, and axios throws on non-2xx by default. Add timeouts, token refresh and error handling.

更新 2026-10-31 · 公式可核验

Differences

Browsers restrict Host/Cookie/User-Agent headers.

Cross-origin needs server CORS; cURL is not restricted.

Complete the code

Add an AbortController timeout.

Check res.ok; refresh the token on 401.

FAQ

Why does the browser request fail?

Usually CORS/preflight; check the Network panel.

Why does axios throw?

It throws on non-2xx by default; adjust validateStatus.

Sources

Related calculators

cURL to CodePaste cURL to generate fetch, axios or Python requests code; parses URL, method, headers and body without sending requests.

More guides

Common cURL FlagsRead guide