Created
March 27, 2019 22:01
-
-
Save bagder/eba1a372298c5b5f63eca1c062914ff0 to your computer and use it in GitHub Desktop.
attempt to reproduce a POST issue
This file contains 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 <curl/curl.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <unistd.h> | |
#define POSTFILE "debugit" | |
#define synurl "localhost" | |
#define ctimeout 10L | |
int main (void) | |
{ | |
struct stat stat; | |
CURL *curl; | |
FILE *f; | |
long res; | |
int r = -1; | |
if (!(f = fopen(POSTFILE, "r"))) | |
return -1; | |
if(fstat(fileno(f), &stat) < 0 || !(curl = curl_easy_init())) | |
goto err; | |
if (curl_easy_setopt(curl, CURLOPT_URL, synurl) || | |
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L) || | |
curl_easy_setopt(curl, CURLOPT_POST, 1L) || | |
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L) || | |
curl_easy_setopt(curl, CURLOPT_READDATA, f) || | |
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)stat.st_size) || | |
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, ctimeout) || | |
curl_easy_setopt(curl, CURLOPT_USERAGENT, "moo")) | |
goto err; | |
if (curl_easy_perform(curl) != CURLE_OK) | |
goto err; | |
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &res); | |
if (res != 200) | |
goto err; | |
r = 0; | |
err: | |
curl_easy_cleanup(curl); | |
fclose(f); | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment