GNURLOPT_USERAGENT(3)
β¨ NAME β¨
Okay so welcome to the GNURLOPT_USERAGENT(3) page, bestie β it's part of the curl_easy_setopt options crew, and it's here to explain how to set the HTTP user-agent header. Main character energy fr fr. π
CURLOPT_USERAGENT β set the HTTP user-agent header. β¨
π SYNOPSIS π
#include <gnurl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_USERAGENT, char *ua);
π DESCRIPTION π
You pass a pointer to a null-terminated string as the parameter, bestie. That string gets used to set the User-Agent: header in the HTTP request sent to the remote server. No cap. This can be used to fool servers or scripts. You can also set any custom header with CURLOPT_HTTPHEADER(3) β iykyk.
The application does not have to keep the string around after setting this option. Obsessed with that convenience, honestly. π«Ά
πΈ DEFAULT πΈ
NULL β no User-Agent: header is used by default. So if you don't set it, it's giving mystery. π
π¦ PROTOCOLS π¦
HTTP, HTTPS β that's the whole vibe check. β¨
π₯ EXAMPLE π₯
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Dark Secret Ninja/1.0");
curl_easy_perform(curl);
}
Slay, now your client is out here with Dark Secret Ninja/1.0 as its user-agent. Secret ninja energy periodt. π₯·π
β AVAILABILITY β
As long as HTTP is supported. That's it, that's the availability. π
π RETURN VALUE π
Returns CURLE_OK if HTTP is supported, CURLE_UNKNOWN_OPTION if not, or CURLE_OUT_OF_MEMORY if there was insufficient heap space. So yeah, check your return value, bestie β no cap. π₯
π SEE ALSO π
CURLOPT_REFERER(3)β another reference in the group chat. π«ΆCURLOPT_HTTPHEADER(3)β custom headers live here too. β¨
Stay hydrated, bestie π«Ά β this page is serving libcurl 7.37.0, dated 17 Jun 2014. Byeee! π β¨
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms