These curl recipes show you how to change the User-Agent HTTP header in curl requests. By default, curl sets the User-Agent header to curl/version but often you need to make requests as if you were a real browser, a Google bot, or some other critter. To do that, use the -A 'User Agent String' command line option.

Change the User Agent to Firefox

curl -A 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0' https://google.com

This recipe uses the -A argument and sets the user agent to Firefox 60, which looks like this Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0.

Change the User Agent to Chrome

curl -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36' https://google.com

Similar to the previous recipe, this recipe sets the user agent to Chrome 76, which looks like this Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36.

Pretend to be a Google Bot

curl -A 'Googlebot/2.1 (+http://www.google.com/bot.html)' https://washingtonpost.com

Often, websites will serve the content to a Google bot (so that they are indexed) but when a real browser requests them, they'll show a paywall. To bypass this, set the user agent to Googlebot.

Remove the User Agent

curl -A '' https://google.com

This recipe passes an empty string '' to the -A command line option. The empty string tells curl to remove the user agent header and not to send User-Agent HTTP header.

Change the User Agent via -H Argument

curl -H 'User-Agent: php/1.0' https://google.com

This recipe shows another way how to change the user agent. Instead of using -A 'User Agent String', it uses -H 'User-Agent: php/1.0'. This argument directly adds the HTTP header field and now the websites will think we're PHP.

Send an Empty User Agent

curl -A '' -H 'User-Agent;' https://google.com

This recipe gets tricky. To send an empty user agent (just the User-Agent: header with no value), first we have to remove curl's own user agent via the -A '' option, and then add an empty header via the -H 'User-Agent;' option. Notice the semicolon ; at the end of the User-Agent string. It must be there as it tells curl that it's an empty header with no value.

Created by Browserling

These curl recipes were written down by me and my team at Browserling. We use recipes like this every day to get things done and improve Browserling. Browserling itself is an online cross-browser testing service powered by alien technology. Check it out!

Secret message: If you love my curl recipe, then I love you, too! Use coupon code CURLLING to get a discount at my company Browserling.