CURLINFO_EFFECTIVE_METHOD.md (1688B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLINFO_EFFECTIVE_METHOD 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_CUSTOMREQUEST (3) 9 - CURLOPT_FOLLOWLOCATION (3) 10 - curl_easy_getinfo (3) 11 - curl_easy_setopt (3) 12 Protocol: 13 - HTTP 14 Added-in: 7.72.0 15 --- 16 17 # NAME 18 19 CURLINFO_EFFECTIVE_METHOD - get the last used HTTP method 20 21 # SYNOPSIS 22 23 ~~~c 24 #include <curl/curl.h> 25 26 CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_EFFECTIVE_METHOD, 27 char **methodp); 28 ~~~ 29 30 # DESCRIPTION 31 32 Pass in a pointer to a char pointer and get the last used effective HTTP 33 method. 34 35 In cases when you have asked libcurl to follow redirects, the method may not be 36 the same method the first request would use. 37 38 The **methodp** pointer is NULL or points to private memory. You MUST NOT 39 free - it gets freed when you call curl_easy_cleanup(3) on the 40 corresponding curl handle. 41 42 # %PROTOCOLS% 43 44 # EXAMPLE 45 46 ~~~c 47 int main(void) 48 { 49 CURL *curl = curl_easy_init(); 50 if(curl) { 51 CURLcode res; 52 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 53 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data"); 54 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); 55 res = curl_easy_perform(curl); 56 if(res == CURLE_OK) { 57 char *method = NULL; 58 curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_METHOD, &method); 59 if(method) 60 printf("Redirected to method: %s\n", method); 61 } 62 curl_easy_cleanup(curl); 63 } 64 } 65 ~~~ 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).