I have application that received data via HTTP POST requests. I'm trying to use libcurl to open a request to this app, send the data and receive the reply back from the app. This is the code I have so far:
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
const int timeout = 30000;
char outputmessage[]="VGhpcyBpcyBqdXN0IGEgbWVzc2FnZSwgaXQncyBub3QgdGhlIHJlYWwgdGhpbmc=";
curl_easy_setopt(curl, CURLOPT_URL, "https://somehost.com/someapp");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, outputmessage);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(outputmessage));
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout/1000);
res = curl_easy_perform(curl);
if(CURLE_OK != res)
{
printf("Error: %s\n", strerror(res));
return 1;
}
// now what?
// cleanup when done
curl_easy_cleanup(curl);
}
return 0;
}
This essentially connects to the server, I get a OK on the curl_easy_perform()
. I can see the connection on Wireshark.
Two questions:
1) Is this the correct way of sending data via a POST, and
2) How do I get the reply from the application.
I thought I need to use curl_easy_recv()
but I can't see how. Any sample code is welcome.
Thanks.