curl-library
Re: Issue With curl_easy_perform
Date: Tue, 04 Apr 2006 09:00:32 -0700
Hi Daniel:
Thanks for responding, I have a dll that uses CreateProcessW to make a call
to an exe, this exe does an HTTP_POST with libcurl, also I have no code in
libcurl that is writing to stdout, I created a callback function using
CURLOPT_WRITEFUNCTION so that I can read some of the data that the server
sends back. I am attaching the code again here, let me know if the code
below in any case should create a popup window.
extern "C" size_t write_data(void *source,size_t size,size_t nmemb,void
*userData)
{
return size * nmemb;
}
int Myclass::uploadFile(std::string receiverURL,std::string path,int
numAttempts)
{
CURL *curl;
CURLcode res;
struct curl_httppost *formpost=NULL;
struct curl_httppost *lastptr=NULL;
struct curl_slist *headerlist=NULL;
char buf[] = "Expect:";
bool delFile = false;
int numAttemptsToUpload=0;
curl_global_init(CURL_GLOBAL_ALL);
/* Fill in the file upload field */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "sendfile",
CURLFORM_FILE, path.c_str(),
CURLFORM_END);
/* Fill in the filename field */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "filename",
CURLFORM_COPYCONTENTS, path.c_str(),
CURLFORM_END);
/* Fill in the submit field too, even if this is rarely needed */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "submit",
CURLFORM_COPYCONTENTS, "send",
CURLFORM_END);
curl = curl_easy_init();
/* initalize custom header list (stating that Expect: 100-continue is
not
wanted */
headerlist = curl_slist_append(headerlist, buf);
/* if we have a handle proceed with the transaction */
if(curl)
{
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
/* what URL that receives this POST */
curl_easy_setopt(curl, CURLOPT_URL, receiverURL.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
res = curl_easy_perform(curl);
/* if we are here we wait
and try the upload again till we are successful
for now we set this to 2 minutes
later it will be configurable
*/
if ( (numAttempts<=defaultMaxAttempts) && (res!=CURLE_OK) )
{
Sleep(sleepTimeout);
uploadFile(receiverURL,path,numAttempts++);
}
/* cleanup */
curl_easy_cleanup(curl);
/* then cleanup the formpost chain */
curl_formfree(formpost);
/* free slist */
curl_slist_free_all (headerlist);
}
return res;
}
This is the code that gets called from the dll, the dll itself gets put
inside a windows application
Let me know if you see anything obvious
>From: Daniel Stenberg <daniel_at_haxx.se>
>Reply-To: libcurl development <curl-library_at_cool.haxx.se>
>To: libcurl development <curl-library_at_cool.haxx.se>
>Subject: Re: Issue With curl_easy_perform
>Date: Tue, 4 Apr 2006 10:26:33 +0200 (CEST)
>
>On Mon, 3 Apr 2006, Saikat Kanjilal wrote:
>
>>noticed that when I put my dll inside a windows app and call it from there
>>it opens up a command window every time, I am guessing this is for
>>libcurl, is there any way to remove this.
>
>libcurl certainly has no code that pops up windows. I guess your
>environment is such that it opens a window if your program writes to stdout
>(or similar) and you have code in libcurl callback that does this.
>
>You could very easily verify this yourself with the use of a debugger.
>
>--
> Commercial curl and libcurl Technical Support: http://haxx.se/curl.html
Received on 2006-04-04