CURLOPT_USERAGENT.md (1435B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_USERAGENT 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_CUSTOMREQUEST (3) 9 - CURLOPT_HTTPHEADER (3) 10 - CURLOPT_REFERER (3) 11 - CURLOPT_REQUEST_TARGET (3) 12 Protocol: 13 - HTTP 14 Added-in: 7.1 15 --- 16 17 # NAME 18 19 CURLOPT_USERAGENT - HTTP user-agent header 20 21 # SYNOPSIS 22 23 ~~~c 24 #include <curl/curl.h> 25 26 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_USERAGENT, char *ua); 27 ~~~ 28 29 # DESCRIPTION 30 31 Pass a pointer to a null-terminated string as parameter. It is used to set the 32 User-Agent: header field in the HTTP request sent to the remote server. You 33 can also set any custom header with CURLOPT_HTTPHEADER(3). 34 35 The application does not have to keep the string around after setting this 36 option. 37 38 Using this option multiple times makes the last set string override the 39 previous ones. Set it to NULL to disable its use again. 40 41 # DEFAULT 42 43 NULL, no User-Agent: header is used. 44 45 # %PROTOCOLS% 46 47 # EXAMPLE 48 49 ~~~c 50 int main(void) 51 { 52 CURL *curl = curl_easy_init(); 53 if(curl) { 54 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 55 56 curl_easy_setopt(curl, CURLOPT_USERAGENT, "Dark Secret Ninja/1.0"); 57 58 curl_easy_perform(curl); 59 } 60 } 61 ~~~ 62 63 # %AVAILABILITY% 64 65 # RETURN VALUE 66 67 curl_easy_setopt(3) returns a CURLcode indicating success or error. 68 69 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 70 libcurl-errors(3).