cURL / Mailing Lists / curl-library / Single Mail


Re: post without specific variable name

From: Daniel Stenberg <>
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",
> 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: Try the chapter named

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 --
Received on 2002-01-24