Skip to content

Instantly share code, notes, and snippets.

@Disassembler0
Last active April 12, 2018 12:18
Show Gist options
  • Select an option

  • Save Disassembler0/56df7dc02c6613b43367df7199b24785 to your computer and use it in GitHub Desktop.

Select an option

Save Disassembler0/56df7dc02c6613b43367df7199b24785 to your computer and use it in GitHub Desktop.
/*
Compile using
gcc libcurl-check-response.c -lcurl -o libcurl-check-response
*/
#include <curl/curl.h>
int main(int argc, char *argv[])
{
CURLcode ret;
CURL *hnd;
FILE *devnull = fopen("/dev/null", "w");
hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_URL, "https://google.com");
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(hnd, CURLOPT_NOBODY, 1L);
curl_easy_setopt(hnd, CURLOPT_HEADER, 1L);
curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.47.0");
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
curl_easy_setopt(hnd, CURLOPT_FILETIME, 1L);
curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, devnull);
ret = curl_easy_perform(hnd);
if(ret == CURLE_OK) {
long response_code;
curl_easy_getinfo(hnd, CURLINFO_RESPONSE_CODE, &response_code);
printf("%ld\n", response_code);
}
curl_easy_cleanup(hnd);
hnd = NULL;
fclose(devnull);
return (int)ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment