Linux/Curl: Change the User Agent

This post will guide you how to change the user agent with cURL command in Linux system. How do I set User Agent in cURL command under Linux operating system. How to modify the current user agent in curl.

The Curl application is a tool to transfer date from a server to another using a number of different protocols. and its mainly protocols are HTTP and HTTPS. and if you wnat to change the User Agent header on the HTTP/HTTPS request, how to achieve it. You can use the curl command to modify the user agent value easily.

Change the User Agent with cURL


You just need to run curl command with -A or –user-agent option to change the User Agent. the syntax is as shown in the example below:

# curl -A "User Agent Here" "http://website.com"

Set User Agent to Mozilla Firefox

you just need to type the following command:

# curl --user-agent Mozila/4.0 google.com

If you want to set curl user agent to the User-Agent found in the Windows Firefox web browser, you just issue the following command:

#curl --user-agent 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0)) Gecko/20100101 Firefox/43.0' yahoo.com

If you want to verify the user agent, just type the following command:

# curl -v --user-agent Mozilla/5.0 yahoo.com |grep -i User-Agent

Outputs:

[root@vultr ~]# curl -v --user-agent Mozilla/5.0 yahoo.com |grep -i User-Agent
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* About to connect() to yahoo.com port 80 (#0)
* Trying 98.138.219.232...
* Connected to yahoo.com (98.138.219.232) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: Mozilla/5.0
> Host: yahoo.com
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Fri, 28 Sep 2018 06:08:11 GMT
< Connection: keep-alive
< Via: http/1.1 media-router-fp1005.prod.media.ne1.yahoo.com (ApacheTrafficServer [c s f ])
< Server: ATS
< Cache-Control: no-store, no-cache
< Content-Type: text/html
< Content-Language: en
< X-Frame-Options: SAMEORIGIN
< Set-Cookie: B=06l67kddqrhab&b=3&s=jv; expires=Sat, 28-Sep-2019 06:08:11 GMT; path=/; domain=.yahoo.com
< Location: https://www.yahoo.com/
< Content-Length: 8
<
{ [data not shown]
100 8 100 8 0 0 87 0 --:--:-- --:--:-- --:--:-- 87
* Connection #0 to host yahoo.com left intact

 

 

You might also like:

Sidebar



back to top