convert curl to http request with authorization header
#include <stdio.h>
#include <curl/curl.h>
int main(void) {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Authorization: Bearer YOUR_ACCESS_TOKEN_HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_URL, "YOUR_URL_HERE");
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
return 0;
}
This C code snippet uses libcurl to perform an HTTP request with an authorization header. It initializes a curl handle (CURL *curl
) and sets the authorization header using curl_slist_append
to add the header to the HTTP request. Replace "Bearer YOUR_ACCESS_TOKEN_HERE"
with your actual access token. Set the URL you want to send the request to by using curl_easy_setopt(curl, CURLOPT_URL, "YOUR_URL_HERE")
. Finally, it performs the request using curl_easy_perform(curl)
and checks for any errors.