#include "test.h"
static char data[]="this is what we post to the silly web server\n";
struct WriteThis {
char *readptr;
size_t sizeleft;
};
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
{
struct WriteThis *pooh = (struct WriteThis *)userp;
if(size*nmemb < 1)
return 0;
if(pooh->sizeleft) {
*(char *)ptr = pooh->readptr[0];
pooh->readptr++;
pooh->sizeleft--;
return 1;
}
return -1;
}
int test(char *URL)
{
CURL *curl;
CURLcode res=CURLE_OK;
struct WriteThis pooh;
pooh.readptr = data;
pooh.sizeleft = strlen(data);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_POST, TRUE);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)pooh.sizeleft);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
curl_easy_setopt(curl, CURLOPT_INFILE, &pooh);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_HEADER, TRUE);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return res;
}