GNURLOPT_USERAGENT(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

✨ 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 🌈


Stay hydrated, bestie 🫢 β€” this page is serving libcurl 7.37.0, dated 17 Jun 2014. Byeee! πŸ’…βœ¨

πŸ“¦ where this page comes from