When making requests using cURL, web servers identify the request source based on a value known as the “User-Agent” string. By default, cURL uses its name and version as the User-Agent. However, in some situations, you may need to imitate a browser or another tool's request or test how servers respond to various User-Agent strings.
Web servers and applications often deliver content based on the User-Agent. For example, a website might present a mobile-optimized version of its content to requests coming from smartphone browsers. Modifying the User-Agent string in cURL allows developers and testers to mimic requests from different clients, aiding in debugging and website behavior analysis.
You can fake the cURL User-Agent string by using the -A or –user-agent option followed by the desired User-Agent string.
Related: advanced-usage \ Related: change-user-agent
$ curl https://www.example.com/
$ curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0" https://www.example.com/
$ curl --user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0" https://www.example.com/
$ curl -I --user-agent "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7" https://www.example.com/
The -I flag sends a HEAD request, which will only return headers, allowing you to observe possible variations in server responses based on User-Agent.
$ curl https://www.example.com/
Comment anonymously. Login not required.