cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Problem with attachment based multiple form!

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 12 Dec 2002 13:02:36 +0100 (MET)

On Wed, 11 Dec 2002, Sanjeev wrote:

> 1) probDescrition.html ( describing my problem )

Please use plain text, both in mail and in documents such as this. I don't
use a browser to read mail and I don't intend to start doing it now either.

First, I modified the 'formfind' script since your HTML example proved it to
be somewhat defect. When fixed, it shows a perfect report on your form HTML.
I'd recommend you to get it and try it. You might notice something new.

[from your HTML doc]

        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
        curl_easy_setopt(curl, CURLOPT_URL,
                                "http://www.yyy.com/qqq/formspage.phtml");
        curl_easy_setopt(curl, CURLOPT_FILE, file);
        curl_easy_setopt(curl, CURLOPT_COOKIEFILE, mfile);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS,
                                "uid=san&pass=san");
        res = curl_easy_perform(curl);

This does not save any received cookies. If I were you, I'd consider doing
that.

> If I ignore the Attachment field I could successfully
> submit the page with:

        curl_easy_setopt(curl, CURLOPT_POSTFIELDS,
        "m_tpc=zzz&m_desc=yyy&m_class=1&frmnum=1&stat=1&continue=Continue");

        res = curl_easy_perform(curl);

If that worked, you're lucky. The <form> tags clearly says that it wants a
multipart formpost and POSTFIELDS does not supply such a post.

You say you failed with:

        curl_easy_setopt(curl, CURLOPT_POSTFIELDS,
                                "m_file='/tmp/myfile.dat'&attSub=Attach");
        res = curl_easy_perform(curl);

... which failed exactly because this is not a multipart formpost.

And regarding your failed second attempt:

        curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "m_file",
                    CURLFORM_FILE, "/tmp/log.txt", CURLFORM_END);
        curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "m_file",
                          CURLFORM_COPYCONTENTS, "/tmp/log.txt", CURLFORM_END);

Why are you passing along two sections using the same name? The form clearly
expects only one field named "m_file" and that is the file. CURLFORM_FILE is
the one you want for this.

        curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "attSub",
                                CURLFORM_COPYCONTENTS, "Attach",
                                CURLFORM_END);
        curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "continue",
                                CURLFORM_COPYCONTENTS, "Continue",
                                CURLFORM_END);

If these four fields were the only ones you provided in your post I'm not
surprised at all it didn't work. The form clearly includes more fields that
you didn't pass along, like "m_class", "frmnum", "att" and "m_desc".

Of course, you might've been leaving them behind for a reason but your doc
didn't mention any such.

> Also strangely what I observed in verbose is

        curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);

> formpost is infact submitting the previous Authentication POSTFIELDS
> instead of these values appended to formadd.

You cannot supply both CURLOPT_HTTPPOST and CURLOPT_POSTFIELDS to the same
request. You need to use one of them. And for this form, CURLOPT_HTTPPOST is
the one you want.

-- 
 Daniel Stenberg -- curl, cURL, Curl, CURL. Groks URLs.
-------------------------------------------------------
This sf.net email is sponsored by:
With Great Power, Comes Great Responsibility 
Learn to use your power at OSDN's High Performance Computing Channel
http://hpc.devchannel.org/
Received on 2002-12-12