Created
March 25, 2021 12:45
-
-
Save rexim/786d0f338a035c46a147fcda330abfea to your computer and use it in GitHub Desktop.
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
// $ gcc `pkg-config --cflags libcurl` -o main main.c `pkg-config --libs libcurl`&& ./main | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <curl/curl.h> | |
int main(void) | |
{ | |
if (curl_global_init(CURL_GLOBAL_DEFAULT) != 0) { | |
fprintf(stderr, "ERROR: could not initialize global CURL state for some reason.\n"); | |
exit(1); | |
} | |
CURL *curl = curl_easy_init(); | |
if (curl == NULL) { | |
fprintf(stderr, "ERROR: could not create easy CURL context\n"); | |
exit(1); | |
} | |
struct curl_slist *chunk = NULL; | |
chunk = curl_slist_append(chunk, "Supa-Secret-Header: lol"); | |
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); | |
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1); | |
// $ while true; do printf "lol\r\nlol\r\n\r\n" | nc -l 8080; done | |
{ | |
const char *const url = "http://localhost:8080/"; | |
curl_easy_setopt(curl, CURLOPT_URL, url); | |
CURLcode res = curl_easy_perform(curl); | |
if (res != CURLE_OK) { | |
fprintf(stderr, "ERROR: CURL GET query of %s has failed: %s\n", | |
url, | |
curl_easy_strerror(res)); | |
} | |
printf("------------------------------\n"); | |
sleep(1); | |
} | |
// $ while true; do printf "lol\r\nlol\r\n\r\n" | nc -l 8081; done | |
{ | |
const char *const url = "http://localhost:8081/"; | |
curl_easy_setopt(curl, CURLOPT_URL, url); | |
CURLcode res = curl_easy_perform(curl); | |
if (res != CURLE_OK) { | |
fprintf(stderr, "ERROR: CURL GET query of %s has failed: %s\n", | |
url, | |
curl_easy_strerror(res)); | |
} | |
printf("------------------------------\n"); | |
sleep(1); | |
} | |
curl_easy_cleanup(curl); | |
curl_global_cleanup(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment