To set the User-Agent string with Curl, you need to use the -A or --user-agent command-line option. When you use Curl to send an HTTP request, it sends the User-Agent string information in the “curl/version.number” format. The default header value in User-Agent: curl/7.54.1. In this example, we are set the User-Agent string to the ReqBin echo URL. Click Run to execute the Curl User-Agent example online and see the results.
Curl (stands for Client URL) is a command-line tool for transferring data to or from the server using URL syntax. Curl allows you to communicate with the server by specifying the target URL and the data you want to send. Curl supports over 25+ protocols, including HTTP, HTTPS, FTP, FTPS, and SFTP, has built-in support for SSL certificates, HTTP Cookies, and more. Curl is ideal for testing APIs and for use in automation scenarios. Curl works on platforms Linux, Windows, and macOS.
What is User Agent?
A user agent is any software acting on behalf of a user that makes a request to a server, receives a response from the server, and processes it. The user agent may have a user interface and interact with the end-user, or it may not have a user interface. In this case, it must provide a procedural or declarative language that can be used to provide a user interface. When the browser connects to the website, it includes the User-Agent string in the HTTP request header. This User-Agent header string varies from browser to browser, but usually includes the name and version of the browser, as well as some information about the operating system it runs on. Web browsers and mobile apps are examples of user agents.
Safari User Agent String Example
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15
Google Chrome User Agent String Example
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36
Mozilla Firefox User Agent String Example
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:89.0) Gecko/20100101 Firefox/89.0
How do I change the default Curl User-Agent string?
The general form of passing a custom User-Agent string to Curl is as follows:
Can I remove the User-Agent string from the Curl request?
Yes, you can use the -H command-line option with the User-Agent header name and no content after the ':' sign. This will force Curl to send the request without the User-Agent header (instead of sending it with an empty value).
Remove Curl User-Agent String
curl -H "User-Agent:" [URL]
Curl User Agent Example
An example of sending a custom User-Agent string to the ReqBin echo URL using the --user-agent command-line parameter: