CURLOPT_USERAGENT(3)

πŸ’… CURLOPT_USERAGENT(3) β€” like, the HTTP user-agent header one

okay bestie, so this is a page from the Library Functions Manual (libcurl girlies rise 🫢) and it's all about telling the internet who you are. or, y'know, who you're pretending to be. main character energy fr fr ✨


🌸 NAME 🌸

CURLOPT_USERAGENT β€” the HTTP user-agent header, and yes it's exactly as iconic as it sounds πŸ’…

✨ SYNOPSIS ✨

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_USERAGENT, char *ua);

πŸ’– DESCRIPTION πŸ’–

So basically πŸŽ€ you pass a pointer to a null-terminated string as the parameter, and that string becomes the User-Agent: header field in the HTTP request that gets sent to the remote server. That's it. That's the whole vibe check. It's literally just you announcing yourself to the server. 🌈

And ngl, if you want to set any other custom header too, you can do that with CURLOPT_HTTPHEADER(3) β€” this option is just the dedicated one for user-agent, iykyk. πŸ‘‘

The good news? The application does not have to keep the string around after setting this option. Set it and forget it, bestie, curl's got it from there πŸ’œ

Also, small but important: using this option multiple times makes the last set string override all the previous ones. And if you set it to NULL, you disable its use again β€” like, back to being a mystery to the server πŸ™ˆ

πŸ¦‹ DEFAULT πŸ¦‹

NULL β€” like, no User-Agent: header is used at all. you're a ghost, a rumour, a vibe with no name πŸ’€

πŸ“ PROTOCOLS πŸ“

This functionality affects http only β€” that's it, that's the list, no cap 🎯

πŸ”₯ EXAMPLE πŸ”₯

okay here's the whole thing, exactly as written, copy it and slay:

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");

    curl_easy_setopt(curl, CURLOPT_USERAGENT, "Dark Secret Ninja/1.0");

    curl_easy_perform(curl);
  }
}

"Dark Secret Ninja/1.0" β€” genuinely iconic string choice, whoever picked it ate and left no crumbs 😭πŸ”₯

⭐ AVAILABILITY ⭐

Added in curl 7.1 β€” ancient, vintage, elder-gen Z of curl versions, we respect her πŸŽ€

🌸 RETURN VALUE 🌸

curl_easy_setopt(3) returns a CURLcode indicating success or error β€” that's your vibe report card 🫢

CURLE_OK (0) means everything was OK. non-zero means an error occurred, so go check libcurl-errors(3) β€” she'll tell you what went wrong πŸ‘‘

πŸ’« SEE ALSO πŸ’«

Go read those too, they're all in the same friend group πŸ’–


✨ that's a wrap bestie ✨ this little cutie is a libcurl page, dated 2026-10-12, and it lives with the rest of the CURLOPT_USERAGENT(3) lore. mwah πŸ’‹ go set a user-agent that's as extra as you are πŸ¦‹

πŸ“¦ where this page comes from