cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: libcurl and curl_formparse

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sun, 22 Apr 2001 18:51:50 +0200 (MET DST)

On Sat, 21 Apr 2001, Andrej Andrejko wrote:

 Please direct future mails in this subject to the mailing list. It allows
others to join in and help, to share their ideas, contribute their suggestions
and spread their wisdom. Keeping discussions on public mailing lists also
allows for others to learn from this (both current and future users thanks to
the web based archives of the mailing list), thus saving me from having to
repeat myself even more. Thanks for respecting this.

> I am having trouble with your libcurl. I wish to transfer a file using
> and HTTP POST file upload.

What kind of post do you want? A RFC1867 post?

>
> Here is my code:
>
>
> HttpPost post;
> HttpPost last;
> HttpPost* ppost = &post;
> HttpPost* plast = &last;
>
> memset(ppost,0,sizeof(HttpPost));
>
> curl_formparse("userfile=@/tmp/karte.jpg",&ppost,&plast);

This is not right. I read the man page right now and I realize it isn't
crystal clear in this matter.

The pointers passed in should be NULL if not previously set by libcurl. It
means this should probably look like:

 HttpPost* ppost = NULL;
 HttpPost* plast = NULL;

 curl_formparse("userfile=@/tmp/karte.jpg",&ppost,&plast);

> curl_easy_setopt(curl, CURLOPT_URL, turl);
> //curl_easy_setopt(curl, CURLOPT_INFILE, inf);
> //curl_easy_setopt(curl, CURLOPT_PUT, 1);
> curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
> curl_easy_setopt(curl, CURLOPT_POST, 1);

^^^^ This sets a normal HTTP POST

> curl_easy_setopt(curl, CURLOPT_HTTPPOST, &last);

^^^^ This sets a rfc1867-style post. You should only use one of them.

And you should pass the pointer to the list not to the last entry. Use the
ppost variable.

> curl_easy_setopt(curl, CURLOPT_INFILESIZE, thumb->filesize);

This is not necessary when doing rfc1867-style posts, as the formparse
function will already fix all that.

> curl_easy_perform(curl);
>
> The last line crashes. How do I call curl_formparse correctly?

With these corrections, I'm sure it'll work as planned!

-- 
      Daniel Stenberg - http://daniel.haxx.se - +46-705-44 31 77
   ech`echo xiun|tr nu oc|sed 'sx\([sx]\)\([xoi]\)xo un\2\1 is xg'`ol
_______________________________________________
Curl-library mailing list
Curl-library_at_lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/curl-library
Received on 2001-04-22