Why Your Converted cURL Command Doesn't Behave Like cURL

Why Your Converted cURL Command Doesn't Behave Like cURL

You paste a cURL command into a converter, you get clean Python, JavaScript, or a raw HTTP request, and it runs. Sometimes it returns the wrong thing. Sometimes it returns the right thing by a path you never intended. Nothing is broken, and nothing looks wrong either.

Here is the reason: a converter translates syntax, not semantics. It reads the flags you wrote, not curl's internal default table. That gap is where every surprise lives.


Getting the command out of your browser

Chrome: open DevTools, go to Network, right-click a request, and choose Copy → Copy as cURL. Chrome offers bash and, on macOS, zsh variants.

Firefox: Network tab, right-click the request, Copy → Copy as cURL.

Safari: enable the Develop menu, open Show Web Inspector → Network, right-click the request, and choose Copy as cURL. It is the least predictable of the three.

All three copy the request in full: method, URL, headers, and body — including Cookie, Authorization, and any CSRF or session header. Read the next section before you paste that anywhere.


Annotated anatomy of a real command

curl -X POST 'https://api.example.com/v1/orders?dry_run=1' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer sk_live_abc123' \
  -d '{"sku":"A-1","qty":2"}'

-X POST is redundant. When -d is present, curl already issues a POST. Dropping -X POST and keeping -d changes nothing.

The single quotes are shell quoting, not part of the URL. Quoting rules are also not portable: PowerShell does not treat `` as a line continuation, and cmd.exe uses double quotes. A command copied from Chrome on macOS can be syntactically broken on Windows for quoting reasons alone.

-H appends, it does not replace. -H 'X-A: 1' -H 'X-A: 2' sends two X-A headers. To suppress one curl would generate, pass the name with an empty value, like -H 'Content-Type:'.

-d sets the body, which is what implies POST, and which also makes curl default Content-Type to application/x-www-form-urlencoded unless a -H flag overrides it.

Flag order is not always commutative. -o out.json before -O and after -O can produce different filenames. Don't let a converter silently reorder your flags.


The divergence table

For each row, the original command did something specific; the converted code does something else.

cURL behaviour What the target library does by default Result after conversion
No -L — curl does not follow redirects Python requests.get/post follows redirects by default Converted code follows redirects your original did not, and may POST to a different host
-L --max-redirs N requests has no cap; you need a Session with a custom adapter A safety limit you set is silently gone
-u user:pass (Basic auth) Varies: requests sends preemptively, Go's http.Client and fetch send nothing until you set the header Either an extra 401 round trip, or credentials sent when you didn't intend
-b / --cookie Needs a cookie jar or an explicit Cookie header — and in browser fetch, Cookie is a forbidden header name Cookies silently dropped; the request arrives as an anonymous one
-k / --insecure TLS verification is on unless you explicitly disable it on the transport A self-signed dev cert that curl accepted now fails — safer, not looser
--data with @filename Many converters treat --data, --data-raw, and --data-binary as one body string File-upload semantics lost; the literal @path goes on the wire
--compressed Only sends Accept-Encoding if that library's defaults do; raw HTTP output carries nothing Server may reply uncompressed, so response size and timing differ from what curl measured
-w / --write-out timing No cross-library equivalent Timing data disappears
-i / -v header dump Client-specific verbose flags, no portable equivalent No substitute; you inspect inside the client instead

The pattern in that table is consistent: the flags people copy most often are exactly the flags a parser can't see. -L, -k, -u, --compressed, and -b change behaviour without ever appearing as a header in the command text.


The secrets hazard — read this before pasting anywhere

A browser's Copy as cURL captures the live request — a production bearer token, a live session cookie, and a CSRF token, written into a single command you are about to hand to a tool.

Paste that into a converter running on someone else's server and you have transmitted a working credential to a third party. The same applies to a bug report, a chat message, a public forum, or — just as importantly — an LLM prompt, which is often backed by a third party too.

Three habits worth keeping:

  1. Copy from an already-sanitized request. Replay it against a test host, or strip Authorization and Cookie before copying.
  2. Rotate anything you have already pasted into a service you don't fully control. Treat the credential as disclosed.
  3. Prefer a converter that does not transmit the command. LangStop's converters run entirely in your browser, so what you paste is never sent to a server. The page loads normally — it is the command that stays local, and that is the property that matters for a credential.

A worked before/after

Start with:

curl 'https://api.example.com/v1/orders?dry_run=1' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer sk_live_abc123' \
  --compressed \
  -d '{"sku":"A-1","qty":2}'

A typical converter gives you:

import requests
 
url = "https://api.example.com/v1/orders?dry_run=1"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer sk_live_abc123",
}
 
response = requests.post(url, headers=headers, json={"sku": "A-1", "qty": 2})
print(response.status_code)

That code translates the request well and the behaviour poorly. Two edits restore parity.

Edit 1 — restore the redirect policy. The original has no -L, so it returned the 302 itself. requests.post follows it by default and hands you the final 200, possibly from a different host, with your Authorization header attached.

response = requests.post(url, headers=headers, json={"sku": "A-1", "qty": 2}, allow_redirects=False)

Edit 2 — assert compression explicitly. --compressed made curl send Accept-Encoding and transparently decompress. Make that visible rather than relying on a library default:

headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer sk_live_abc123",
    "Accept-Encoding": "gzip",
}

If your command had a Cookie header, prefer a Session over a literal header — but in browser fetch the browser strips Cookie regardless, and you need its own cookie store.


Flags with no equivalent at all

Delete these and reproduce the intent by hand:

  • -w / --write-out — timing, size, and status templates. Measure inside the target client.
  • -i / --include and -v / --verbose — connection and header dumps.
  • --trace / --trace-ascii — full wire-level protocol dumps.
  • --retry and --retry-delay — no portable equivalent; you need an explicit retry loop.
  • --resolve and --connect-to — DNS pinning, which in a target library is a transport-level socket option, not a request option.
  • --limit-rate and --max-time — timeouts map imperfectly. requests has timeout, but a rate limit has no analogue.

If a flag you rely on is on this list, note it in a comment where the code lives. A converted command with its intent documented is far more useful than one that looks complete and isn't.


Method semantics survive; their meaning doesn't

PUT is idempotent and replaces the resource at that URL. PATCH applies a partial update and is not guaranteed to be idempotent. A converter preserves the verb and says nothing about that distinction.

The consequence: if a PATCH is retried — by your retry logic, an impatient user, a flaky network — an endpoint that increments a counter increments it twice. The fix belongs in the API: send If-Match with the ETag you read, and have the server reject the write when the representation has moved on. If you cannot change the server, make the operation idempotent with a client-supplied idempotency key.


FAQ

Why does my converted Python follow redirects when my curl command didn't? Because requests follows redirects by default and curl does not. Your original returned the redirect itself; the converted code hides it. Pass allow_redirects=False.

Why are my cookies gone? Because --cookie state lives in curl's cookie jar, which no converter can see. Reconstruct it as a Cookie header — and if you're converting to browser fetch, note that Cookie is a forbidden header name, so the browser drops it and you must rely on its own cookie store.

Is it safe to paste a cURL command into an online converter? Only if it contains nothing secret. Browser-copied commands routinely include Authorization and Cookie. Strip them first, rotate them afterwards if you already pasted them somewhere, or use a converter that runs in your browser so the command is never transmitted.

What's the difference between --data and --data-raw? --data strips carriage returns and newlines from the file it reads; --data-raw does not. That matters for byte-exact payloads. A third case, --data-binary, is the one you want for file uploads — and the one where @filename actually means "read this file". If your converter collapsed all three into one string, that is a real semantic loss, not a formatting detail.

Does converting change PUT versus PATCH semantics? It preserves the method but not its meaning. PUT replaces and is idempotent; PATCH merges and usually isn't. A retried PATCH can apply twice. Guard it with If-Match and an ETag, or an idempotency key.


Put it together

Conversion gets you from a command you know works to a first draft of code you have to read. The gap between those two states is exactly the table above. Check redirect policy, check TLS, check cookies, check method semantics — then paste the result into LangStop's cURL to Python converter or cURL to JavaScript fetch converter, both of which build the code in your browser without transmitting the command.

Once you have the translated request, fire it and inspect the response directly — the LangStop REST client sends requests from the browser, so it is subject to the same CORS rules as any browser request. To go the other direction, the curl command builder is faster. To replay in Postman or another HTTP client, convert to raw HTTP or HAR instead.

If the flags involved are new to you rather than to the conversion problem, How to Use cURL covers the fundamentals and What Is HTTP? explains the methods and status codes these flags manipulate.


  • cURL to Python — Python requests output, where redirect and auth defaults differ most from curl's.
  • cURL to JavaScript fetch — browser fetch, and the fastest way to see that Cookie headers cannot survive the trip.
  • cURL to Raw HTTP Request — strips the abstraction away, the most faithful check of what was sent.
  • cURL to Node fetch — when you need Node's fetch, where forbidden-header limits do not apply.
  • cURL Converter Hub — every supported target: wget, httpie, PowerShell, C#, Go, Java, PHP, and more.
  • REST API Client — send the converted request and read the real response.