curl-library
Can't log POST requests via CURLOPT_VERBOSE?
Date: Wed, 13 Oct 2004 15:41:49 -0700 (PDT)
I would really like to be able to log my POST requests, but when I use CURLOPT_VERBOSE and CURLOPT_STDERR below, the file is always empty.
Is this supported?
-dp-
#define DEBUG 1 #force it to be true...using -DDEBUG in makefile had no effect
/* Adapted from http://curl.haxx.se/libcurl/c/libcurl-tutorial.html#Upload
* and http://curl.haxx.se/libcurl/c/libcurl-tutorial.html#HTTP
* and http://curl.haxx.se/lxr/source/docs/examples/postit2.c
* with guidance from http://curl.siamu.ac.th/libcurl/c/curl_formadd.html
*/
bool bUploadFileViaPOST( const char *sURL,
const char *sTransactionID,
const char *sFilePathOnLocalMachine,
const char *sFileContents,
const unsigned int uiNumBytesToUpload )
{
CURL *curl_handle;
bool bOK = false;
struct curl_httppost *pStartOfPOSTPayload = NULL;
struct curl_httppost *pEndOfPOSTPayload = NULL;
#ifdef DEBUG
FILE *pFile = fopen("CURL_POST.log", "w");
#endif
/*curl_global_init(CURL_GLOBAL_ALL); done for us, according to http://curl.siamu.ac.th/libcurl/c/curl_global_init.html */
/* Make an initial payload section called "trans" that contains only the transaction ID */
curl_formadd(&pStartOfPOSTPayload,
&pEndOfPOSTPayload,
CURLFORM_COPYNAME, "trans",
CURLFORM_COPYCONTENTS, sTransactionID,
CURLFORM_END);
/* Fill in the filename field */
curl_formadd(&pStartOfPOSTPayload,
&pEndOfPOSTPayload,
CURLFORM_COPYNAME, "upload",
CURLFORM_BUFFER, sFilePathOnLocalMachine, /* filename to give to buffer contents upon upload */
CURLFORM_BUFFERPTR, sFileContents,
CURLFORM_BUFFERLENGTH, (long) uiNumBytesToUpload,
CURLFORM_END);
curl_handle = curl_easy_init();
if (curl_handle) {
curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, pStartOfPOSTPayload);
/* for thread safety; done once per handle */
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, true);
/* what URL that receives this POST */
curl_easy_setopt(curl_handle, CURLOPT_URL, sURL);
/* some servers don't like requests that are made without a user-agent
field, so we provide one */
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
#ifdef DEBUG
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, true);
curl_easy_setopt(curl_handle, CURLOPT_STDERR, pFile);
#endif
bOK = (curl_easy_perform(curl_handle) == CURLE_OK);
/* always cleanup */
curl_easy_cleanup(curl_handle);
/* then cleanup the pStartOfPOSTPayload chain */
curl_formfree(pStartOfPOSTPayload);
}
return bOK;
}
Received on 2004-10-14