CURLINFO_EFFECTIVE_METHOD(3)

✨ CURLINFO_EFFECTIVE_METHOD ✨

okay bestie, so this is a page from the Library Functions Manual (iconic, we love a libcurl moment) and it's all about CURLINFO_EFFECTIVE_METHOD β€” literally the last HTTP request method that got used. no cap, that's the whole vibe. πŸŽ€


🌸 NAME 🌸

CURLINFO_EFFECTIVE_METHOD β€” the last used HTTP request method πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <curl/curl.h>

CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_EFFECTIVE_METHOD,
                           char **methodp);

πŸ’– DESCRIPTION πŸ’–

so you pass in a pointer to a char pointer, right? and you get back the last used effective HTTP method. that's it, that's the tea. ✨

and here's the sneaky part: if you've told libcurl to follow redirects, the method you end up with may not be the same method the first request would use. it's giving plot twist. 😭 so don't assume, okay?

the methodp pointer is either NULL or it points to private memory β€” and you must not free it. nope. not you, not ever. πŸ™ˆ that memory gets freed automatically when you call curl_easy_cleanup(3) on the corresponding curl handle. libcurl's got it handled, trust. 🫢


🌈 PROTOCOLS 🌈

this functionality affects http only. that's the whole list. http bestie, nobody else. πŸ’€


⭐ EXAMPLE ⭐

here's the moment you've all been waiting for, the code, look at her go πŸ‘‘

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data");
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
    result = curl_easy_perform(curl);
    if(result == CURLE_OK) {
      char *method = NULL;
      curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_METHOD, &method);
      if(method)
        printf("Redirected to method: %s\n", method);
    }
    curl_easy_cleanup(curl);
  }
}

like, she sets the URL, sets CURLOPT_POSTFIELDS to "data", turns on CURLOPT_FOLLOWLOCATION with 1L, runs it, and if result == CURLE_OK she grabs the method and prints "Redirected to method: %s\n". then cleanup. main character energy fr fr. πŸ”₯


🌸 AVAILABILITY 🌸

added in curl 7.72.0. so if you're on anything older, sorry babe, she's not there yet. πŸ’œ


🧚 RETURN VALUE 🧚

curl_easy_getinfo(3) returns a CURLcode indicating success or error.

  • CURLE_OK (0) means everything was OK πŸŽ‰
  • anything non-zero means an error occurred β€” go check libcurl-errors(3) and figure out what went down 😭

πŸ”₯ SEE ALSO πŸ”₯

go read them, iykyk πŸ“šβœ¨


and that's the page!! this lil gem comes to you from libcurl, dated 2026-10-12, living under the title CURLINFO_EFFECTIVE_METHOD(3) β€” ok bye bestie, go get that method πŸ’…πŸ’–πŸ¦‹

πŸ“¦ where this page comes from