curl-library
Re: Problem with attachment based multiple form!
Date: Thu, 12 Dec 2002 23:58:48 -0800 (PST)
Thank you sir!
Firstly, let me say sorry for, not reading
curl_formadd doc before coming
to you. I just followed your postit2.c example file
then.
Next, after going through docs and your today's mail,
i suspect that, the
html code i sent might be *CONFUSING* cURL. I say this
because, what ever
you said should'nt happen are working fine for me. And
now I'm 99% Successful
in my project, excepting few glitches, for which you
should help me out! if
possible.
Yesterday's Problem::
------------------------------------------------------------------------------
There is a libcurl.so.2 (131KB file) in the /usr/lib (
which might've come
with the Mandrake distrubtion ) and now the current
libcurl package is defaulted
to /usr/local/lib ( curl-7.10.3-pre1's libcurl.so.2 is
580KB ). while running
yesterday's program, it is running with 131KB file (
from gdb ). And hence the
problem.
Since we are checking for libcurl version with
#if LIBCURL_VERSION_NUM < 0x070900
which i guess might be taken from <curl/curl.h>
Since the core is in the libcurl.so, cant we check for
something else from that
libcurl.so file to check the version number, along
with LIBCURL_VERSION_NUM
from curl/curl.h. I'm saying this because there might
be some people, who may
face this problem, ( or ) my program might not work on
other machine, with
similiar problem. It will be possible for us to warn
them.
Well, i dont know if it is possible to check from the
binary file 'libcurl.so'
during compiling.
------------------------------------------------------------------------------
>> 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.
What else should I do for this Sir!
------------------------------------------------------------------------------
>> 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.
Well! I'm really lucky! Because I continue working
with the same code and its
working right for me.
------------------------------------------------------------------------------
> 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".
Yes in my current working code, i'm using POSTFIELDS
successfully to submit
these left ones, after using HTTPPOST for submitting
the Attachment.
------------------------------------------------------------------------------
>> 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.
This is where i said cURL might being confused.
Because after changing the
libcurl.so with the right version, i dont have this
above problem. It *IS*
submitting the page.
May be by saying: "You cannot supply both
CURLOPT_HTTPPOST and CURLOPT_POSTFIELDS
to the same request" this you might have meant the
same *REQUEST* i.e,
only one curl_easy_perform() for both of them
together!
But i'm using, as you can see in the Attached code,
individual perform.
one curl_easy_perform() after HTTPPOST and the other
after POSTFIELDS.
This way, in a particular session, the page is being
submitted 4 times, with
4th time submission being the FINAL submission. That
is, the data is inserted
into mysql at this point, with all the previously
submitted values.
Though I'm comfortable with this, If you can please
suggest me, if I can reduce
the number of submissions from 4.
-------------------------------------------------------------------------------
Today's Problem::
Now that the attached code is working fine for me, i
have few questions:
1) By the following Code::
curl_formadd(&post, &last, CURLFORM_COPYNAME,
"pictures",
CURLFORM_FILE, "my-face.jpg",
CURLFORM_FILE, "your-face.jpg",
CURLFORM_END);
Did you mean that the form had two input boxes for
file input ( browse file )
for the same name=pictures
if that is right. I dont have any further question
regd. this. But if it meant
that i can submit two files with only one input box (
practically impossible
with a regular browser ), then it is not working for
me. I can only submit one
file.
Is ther any alternative to submit two or more files,
with one input box as said
above as per my html page??
_______________________________________________________________________________
2) While Coding I dont have any idea of how many
Attachments a request is going
to submit. So i took a way out to do this:
for(i = 0; i < numatt; i++) {
curl_easy_setopt(curl, CURLOPT_HTTPPOST,
post);
res = curl_easy_perform(curl);
post->contents = myArray[i];
}
where 'numatt' is the number of attachments,
myArray[] holds the individaul attachment
paths.
post is descendant of HttpPost struct;
And this is working quite well for me. But 2
exceptions:
a) the page is being submitted those many times there
are attachments ( for which,
may be we dont have any other alternative! )
b) curl_formfree(post) is segfaulting for me. may be
because i'm manually changing
the contents of post->contents. So, i needed to
comment this line to proceed
any further, as you see in the attached c file.
// Program received signal SIGSEGV, Segmentation
fault.
// 0x400d3bcd in free () from /lib/libc.so.6
--------------------------------------------------------------------------------
Well these are the only problems for me right now.
other than that i'm done pretty
much with my coding!
And Ofcourse, I'm comfortable with the current code i
attached, and can go with it.
Thank you very much for your Support and for your
wonderful package in cURL!
Bye
Sanjeev
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
-------------------------------------------------------
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/
- application/x-unknown attachment: httpPost.c