xref: /curl/docs/libcurl/opts/CURLOPT_USERAGENT.md (revision e3fe0200)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_USERAGENT
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_CUSTOMREQUEST (3)
9  - CURLOPT_HTTPHEADER (3)
10  - CURLOPT_REFERER (3)
11  - CURLOPT_REQUEST_TARGET (3)
12Protocol:
13  - HTTP
14---
15
16# NAME
17
18CURLOPT_USERAGENT - HTTP user-agent header
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25CURLcode curl_easy_setopt(CURL *handle, CURLOPT_USERAGENT, char *ua);
26~~~
27
28# DESCRIPTION
29
30Pass a pointer to a null-terminated string as parameter. It is used to set the
31User-Agent: header field in the HTTP request sent to the remote server. You
32can also set any custom header with CURLOPT_HTTPHEADER(3).
33
34The application does not have to keep the string around after setting this
35option.
36
37# DEFAULT
38
39NULL, no User-Agent: header is used by default.
40
41# EXAMPLE
42
43~~~c
44int main(void)
45{
46  CURL *curl = curl_easy_init();
47  if(curl) {
48    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
49
50    curl_easy_setopt(curl, CURLOPT_USERAGENT, "Dark Secret Ninja/1.0");
51
52    curl_easy_perform(curl);
53  }
54}
55~~~
56
57# AVAILABILITY
58
59As long as HTTP is supported
60
61# RETURN VALUE
62
63Returns CURLE_OK if HTTP is supported, CURLE_UNKNOWN_OPTION if not, or
64CURLE_OUT_OF_MEMORY if there was insufficient heap space.
65