cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: post without specific variable name

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 24 Jan 2002 15:13:48 +0100 (MET)

On 24 Jan 2002, Robin Ericsson wrote:

> > Instead of posting the (working) java code, why don't you instead show us
> > the C code that doesn't work?
>
> struct HttpPost *formpost = NULL, *lastptr = NULL;
>
> curl_formadd(&formpost, &lastptr,
> // CURLFORM_COPYNAME, "variable",
> CURLFORM_COPYCONTENTS, "some string",
> CURLFORM_END);
>
> curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &errorbuf);
> curl_easy_setopt(curl, CURLOPT_FILE, &retval);
> curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
> curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
> curl_easy_setopt(curl, CURLOPT_URL, "http://some.url/");
>
> int res = curl_easy_perform(curl);
>
>
> this ends up in a GET request, however, if I remove the comment on
> COPYNAME, curl makes a POST request.

I would like to suggest that you read libcurl-the-guide, available online
here: http://curl.haxx.se/libcurl/c/the-guide.html. Try the chapter named
"HTTP POSTing".

The problem with your attempt above is that you're doing a multipart
formpost. Multipart formposts are mime-style posts and they *do* have names
and contents.

Your javaprogram didn't seem to do a multipart formpost, so I think you
should focus more on the regular HTTP POST.

Translating your code from above would produce something in this style:

  curl_easy_setopt(curl, CURLOPT_FILE, &retval);
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
  curl_easy_setopt(curl, CURLOPT_POSTFIELD, datapointer);
  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, datalength );
  curl_easy_setopt(curl, CURLOPT_URL, "http://some.url/");

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
Received on 2002-01-24