Created
August 24, 2021 11:45
-
-
Save emadflash/2b702135c80b9e9c2a51ce960b880780 to your computer and use it in GitHub Desktop.
Get request with libcurl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <curl/curl.h> | |
CURL* xcurl_easy_init() { | |
CURL* curl = curl_easy_init(); | |
if (!curl) exit(0); | |
return curl; | |
} | |
#define TARGET_URL "https://curl.se/libcurl/c/CURLINFO_RESPONSE_CODE.html" | |
int main(int argc, char** argv) { | |
CURL* curl = xcurl_easy_init(); | |
curl_easy_setopt(curl, CURLOPT_URL, TARGET_URL); | |
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L); | |
curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/7.42.0"); | |
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L); | |
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L); | |
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L); | |
char* url; | |
long response_code; | |
double elapsed; | |
curl_easy_perform(curl); | |
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); | |
curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &elapsed); | |
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url); | |
printf("\nURL: %s \nCODE: %d \n\TIME: %d\n", url, response_code, elapsed); | |
curl_easy_cleanup(curl); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment