CURLINFO_RESPONSE_CODE.md (1595B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLINFO_RESPONSE_CODE 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLINFO_HTTP_CONNECTCODE (3) 9 - curl_easy_getinfo (3) 10 - curl_easy_setopt (3) 11 Protocol: 12 - HTTP 13 - FTP 14 - SMTP 15 - LDAP 16 Added-in: 7.10.8 17 --- 18 19 # NAME 20 21 CURLINFO_RESPONSE_CODE - get the last response code 22 23 # SYNOPSIS 24 25 ~~~c 26 #include <curl/curl.h> 27 28 CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_RESPONSE_CODE, long *codep); 29 ~~~ 30 31 # DESCRIPTION 32 33 Pass a pointer to a long to receive the last received HTTP, FTP, SMTP or LDAP 34 (OpenLDAP only) response code. This option was previously known as 35 CURLINFO_HTTP_CODE in libcurl 7.10.7 and earlier. The stored value is zero if 36 no server response code has been received. 37 38 Note that a proxy's CONNECT response should be read with 39 CURLINFO_HTTP_CONNECTCODE(3) and not this. 40 41 # %PROTOCOLS% 42 43 # EXAMPLE 44 45 ~~~c 46 int main(void) 47 { 48 CURL *curl = curl_easy_init(); 49 if(curl) { 50 CURLcode res; 51 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 52 res = curl_easy_perform(curl); 53 if(res == CURLE_OK) { 54 long response_code; 55 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); 56 } 57 curl_easy_cleanup(curl); 58 } 59 } 60 ~~~ 61 62 # NOTES 63 64 The former name, CURLINFO_HTTP_CODE, was added in 7.4.1. Support for SMTP 65 responses added in 7.25.0, for OpenLDAP in 7.81.0. 66 67 # %AVAILABILITY% 68 69 # RETURN VALUE 70 71 curl_easy_getinfo(3) returns a CURLcode indicating success or error. 72 73 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 74 libcurl-errors(3).