Setting the User-Agent for Curl Request [C#/.NET Code]

You can use the -A or --user-agent command-line option to pass your User-Agent string to Curl. By default, Curl sends its User-Agent string to the server in the following format: "curl/version.number". For example, when you use the Curl tool version 7.54.1, it sends the "User-Agent: curl/7.54.1" HTTP header to the server. In this User-Agent Curl example, we send a custom User-Agent string to the ReqBin echo URL using the -A command line option. Click Run to execute the Curl User-Agent example online and see the results. The C#/.NET code was automatically generated for the Curl User Agent example.
Setting the User-Agent for Curl Request [C#/.NET Code] Run
curl https://reqbin.com/echo
   -A "ReqBin Curl Client/1.0"
Updated: Viewed: 38192 times
C#/.NET code for Curl User Agent example

C#/.NET code for Curl User Agent Example

This C#/.NET code snippet was generated automatically for the Curl User Agent example.
<< Back to the Curl User Agent example

What is Curl?

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, and 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 many platforms, such as Linux, Windows, and macOS.

What is User-Agent?

A user agent is any software that acts on behalf of a user, making requests to a server, receiving responses from the server, and processing them. Web browsers and mobile apps are examples of user agents. When a browser connects to a 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's running on.

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:

Change Curl User-Agent String
curl -A "product/version" [URL]
curl --user-agent "product/version" [URL]
curl -H "User-Agent: product/version"

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]

How to send a custom User-Agent string with Curl?

Below is an example of sending a custom User-Agent string to the ReqBin echo URL using the --user-agent command-line parameter:

Custom Curl User-Agent String Example
curl --user-agent "ReqBin/1.0" https://reqbin.com/echo"

Curl User-Agent Examples

The following are examples of the User-Agent string for popular browsers:

Sending User-Agent String

You can send a specific User-Agent string with the curl using the -A or --user-agent option followed by the User-Agent string.

Curl User Agent Example
curl https://reqbin.com/echo
   -A "User-Agent String"

Safari User-Agent String

Below is an example of a User-Agent string for Safari:

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

Below is an example of a User-Agent string for Google Chrome:

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

Below is an example of a User-Agent string for Mozilla Firefox:

Google Chrome User Agent String Example
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:89.0) Gecko/20100101 Firefox/89.0

See also

Generate code snippets for C#/.NET and other programming languages

Convert your Curl User Agent request to the PHP, JavaScript/AJAX, Node.js, Curl/Bash, Python, Java, C#/.NET code snippets using the C#/.NET code generator.