CURLOPT_USERNAME.md (2214B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_USERNAME 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_HTTPAUTH (3) 9 - CURLOPT_PASSWORD (3) 10 - CURLOPT_PROXYAUTH (3) 11 - CURLOPT_USERPWD (3) 12 Protocol: 13 - All 14 Added-in: 7.19.1 15 --- 16 17 # NAME 18 19 CURLOPT_USERNAME - username to use in authentication 20 21 # SYNOPSIS 22 23 ~~~c 24 #include <curl/curl.h> 25 26 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_USERNAME, 27 char *username); 28 ~~~ 29 30 # DESCRIPTION 31 32 Pass a char pointer as parameter, which should be pointing to the 33 null-terminated username to use for the transfer. 34 35 CURLOPT_USERNAME(3) sets the username to be used in protocol 36 authentication. You should not use this option together with the (older) 37 CURLOPT_USERPWD(3) option. 38 39 When using Kerberos V5 authentication with a Windows based server, you should 40 include the domain name in order for the server to successfully obtain a 41 Kerberos Ticket. If you do not then the initial part of the authentication 42 handshake may fail. 43 44 When using NTLM, the username can be specified simply as the username without 45 the domain name should the server be part of a single domain and forest. 46 47 To include the domain name use either Down-Level Logon Name or UPN (User 48 Principal Name) formats. For example, **EXAMPLE\user** and 49 **user@example.com** respectively. 50 51 Some HTTP servers (on Windows) support inclusion of the domain for Basic 52 authentication as well. 53 54 To specify the password and login options, along with the username, use the 55 CURLOPT_PASSWORD(3) and CURLOPT_LOGIN_OPTIONS(3) options. 56 57 The application does not have to keep the string around after setting this 58 option. 59 60 # DEFAULT 61 62 blank 63 64 # %PROTOCOLS% 65 66 # EXAMPLE 67 68 ~~~c 69 int main(void) 70 { 71 CURL *curl = curl_easy_init(); 72 if(curl) { 73 CURLcode res; 74 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin"); 75 76 curl_easy_setopt(curl, CURLOPT_USERNAME, "clark"); 77 78 res = curl_easy_perform(curl); 79 80 curl_easy_cleanup(curl); 81 } 82 } 83 ~~~ 84 85 # %AVAILABILITY% 86 87 # RETURN VALUE 88 89 curl_easy_setopt(3) returns a CURLcode indicating success or error. 90 91 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 92 libcurl-errors(3).