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
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms