How to Set or Change User Agent with curl

October 15, 2020

Introduction

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.

How to set or change user agent with curl.

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 curl command.

Change User Agent with curl

To change the curl user agent to a different browser, add the -A 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 --user-agent option with the following command syntax:

curl --user-agent "user-agent-name-here" url

Alternatively, run the command line option -H 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.

Conclusion

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.

Don’t miss out on our other curl guides such as how to send a delete request with curl.

Was this article helpful?
YesNo
Sofija Simic
Sofija Simic is an experienced Technical Writer. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.
Next you should read
How to Make curl Ignore Certificate Errors
October 13, 2020

Learn how to make curl ignore certificate errors by adding the required option to the command. Ignoring...
Read more
Ultimate Guide to Types of SSL Certificates
August 20, 2020

While they all encrypt data, not all SSL certificates provide the same features to their users. Learn about...
Read more
How to Install SSL Certificate on NGINX
March 25, 2020

Install an SSL Certificate on NGINX to ensure a safe connection between your web server and browser. Encrypt...
Read more
How to Generate a Certificate Signing Request (CSR) With OpenSSL
May 22, 2019

A Certificate Signing Request (CSR) is the first step in setting up an SSL Certificate on your website. An...
Read more