Curl User Agent Example

Every curl request announces itself as curl. Usually that is fine. When a server treats clients differently, or blocks command-line tools, -A lets you say something else.

Last updated . How this page is checked.

The command

curl -A "my-app/1.4 (ops@example.com)" https://httpbin.org/user-agent

Opens the request console with this request filled in. It is sent from api-tester.com's server rather than from your machine, so it shows what the endpoint returns, not how your own network or curl build behaves.

What the flags do

FlagWhat it does
-A stringSet the User-Agent. Long form: --user-agent.
-H "User-Agent: string"Does the same thing through the generic header flag.
-A ""Send no User-Agent header at all.

The default and how to change it

Out of the box curl sends User-Agent: curl/ followed by its version number. -A replaces that for one command. To change it for every command, put a user-agent = "..." line in ~/.curlrc.

For your own scripts and bots, identify the software and give a way to contact you. Operators are far more willing to raise a limit or whitelist a client that says who it is than one pretending to be Chrome.

curl https://httpbin.org/user-agent                      # {"user-agent": "curl/8.x.x"}
curl -A "inventory-sync/2.1 (+https://example.com/bot)" https://httpbin.org/user-agent
curl -A "" -v -o /dev/null https://httpbin.org/get        # no User-Agent line

Testing what a browser would get

Servers sometimes return different markup, redirects or even status codes depending on the User-Agent: a mobile layout, a bot-detection page, a 403. Sending a browser's string reproduces that branch from the terminal.

It only goes so far. Bot detection also looks at header order, TLS handshake details and whether JavaScript runs, none of which a User-Agent string changes. If a site still refuses a request that carries a browser string, the User-Agent was not what it was checking.

curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Safari/537.36" \
  -I https://example.com/

Common mistakes

  • The User-Agent is not authentication. Anyone can send any string; never gate access on it.
  • With -L the same User-Agent is sent on every hop, including to other hosts.
  • Some APIs require one. A request with an empty or missing User-Agent can be rejected with 403.

Related curl examples

More under Headers

References

These links leave api-tester.com, which is independent of the projects they point to.

FAQ

How do I set the user agent in curl?

Use -A followed by the string, for example curl -A "my-app/1.0" URL. -H "User-Agent: my-app/1.0" is equivalent.

What is the default curl user agent?

curl/ followed by the version number, for example curl/8.5.0.

Why does a website block my curl request?

Some servers reject the default curl User-Agent or apply bot detection. Setting a descriptive User-Agent may help, but detection that inspects TLS and headers cannot be bypassed by changing the string alone.