A User-Agent (UA) string is information included in the HTTP header, acting on behalf of a user. When you connect to a website from a browser, the UA informs the website from which browser the request is coming from, its version number and operating system.
A server may respond differently to specific user agents. Therefore, you might find yourself needing to change the UA string.
In this tutorial, learn how to set or change the user agent with
Curl User Agent
When you use
curl to send a HTTP request, it sends the user agent information in the “curl/version.number” format.
The latest stable version at the time of writing is 7.72. 0. Therefore, the UA string in the HTTP request would be: “curl/7.72.0″.
There are several ways to set or change the user agent with the
Change User Agent with curl
To change the curl user agent to a different browser, add the
<strong>-A</strong> option with the wanted user agent string:
curl -A "user-agent-name-here" [URL]
To send a request to the webpage example.com by emulating the Firefox 81 user agent, you would run:
curl -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" https://example.com/"
Note: For a full list of options, see user agent strings for different browsers on a Linux system.
You can also use the
<strong>--user-agent</strong> option with the following command syntax:
curl --user-agent "user-agent-name-here" url
Alternatively, run the command line option
<strong>-H</strong> that takes a single parameter of an extra header to include in the curl request:
curl -H "User-Agent: user-Agent-Name-Here"
Note: Need to ignore SSL certificate checks for your latest project? Check out how to make curl ignore certificate errors.
You should now know how to change the user agent with curl and set it to the wanted browser. Doing so allows you to overpass possible blocks or content changes that may appear due to using curl.