22

I'm attempting using curl to monitor the contents of a page served by a remote HTTP server (which I have very little control over), and for some reason the server is returning different results depending on what machine I'm running curl from. I suspect this might be due to a difference in the user agent strings curl is using on each machine.

How do I check (not set) what user agent string curl is sending to the remote server in its HTTP requests?

3 Answers 3

34

Use the --verbose option to see all the headers sent by curl, including User-Agent:

A line starting with '>' means "header data" sent by curl

For example:

$ curl --verbose 'http://www.google.com/'
> GET / HTTP/1.1
> User-Agent: curl/7.37.0
> Host: www.google.com
> Accept: */*
0
3

Try this

curl ifconfig.me/ua

However the output would be "Curl and your curl version"

for example:

curl/7.64.0 
3
  • 1
    This unnecessarily returns an extraneous trailing character.
    – Asclepius
    Jul 28, 2021 at 6:01
  • It returns nothing for me...perhaps its returning an invisible newline character as the previous comment suggests?
    – Jarmos
    Oct 31, 2023 at 17:12
  • The "return" character works on Windows but not under Linux
    – Supersharp
    Mar 12 at 13:36
0

You can also call the JSON service https://ifconfig.co:

curl ifconfig.co/json -s | grep  "raw_value"

It will return the full user-agent string.

Exemple of answer for curl version 8.1.2:

"raw_value": "curl/8.1.2"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.