curl-library
STDOUT and libcurl
Date: Fri, 15 Oct 2010 14:31:15 -0700
Hi,
Take a look at this standalone code, where HTTP POST is successful, but the return code of curl_easy_perform() is always 23 (WRITE ERROR). I need to close stdin, stdout and stderr. If I don't close stdout, return code is 0. Why is this ? And how can I solve this issue ? I'm using libcurl 7.21.1 and RedHat 5. I tried MUTE. but it has been obsoleted. Is there any equivalent options for MUTE ?
-Vaanthi
#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
// Required by for routine
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h> // Declaration for exit()
using namespace std;
main()
{
fclose(stdin);
fclose(stdout);
fclose(stderr);
{
// Code only executed by child process
CURL *curl;
CURLcode res;
static const char *postthis="moo mooo moo moo";
curl = curl_easy_init();
if(curl) {
FILE *dr = fopen("./result","w");
if (dr != 0) {
curl_easy_setopt(curl, CURLOPT_STDERR, dr );
}
curl_easy_setopt(curl, CURLOPT_URL, "http://www.postbin.org/1boaixh");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis);
/* if we don't provide POSTFIELDSIZE, libcurl will strlen() by
itself */
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(postthis));
res = curl_easy_perform(curl);
fprintf (dr, "Result %d", res );
fclose(dr);
/* always cleanup */
curl_easy_cleanup(curl);
}
}
}
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-10-15