cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: HTTP POST not working with servlet

From: Anibal Jodorcovsky <anibal_at_videotron.ca>
Date: Mon, 3 Jun 2002 20:13:06 -0400

Thanks for the prompt reply!

Actually I'm not using multi-part formposts. Just a regular POST with one
form and three fields with data.

I might be confused here then as to the diff between regular posts and
multi.

> You mean if you fill in the data with a browser and press submit? Are you
> making that form a multi-part one then?

Yes, I have an .html with a form inside and then I press submit. No, it's
not a multi-part form as far I can see. It's just this:

<form method="POST"
action="http://anibaltest1/SeriesMover/SeriesMover.SeriesMoverServlet">
<INPUT type="hidden" name="action" value="getSeries"">

<INPUT TYPE="submit">
</form>

I'm sending only one field of the form here and I get it ok from the
servlet. When I try curl I don't get it at all.

> I guess you meant 'post' and not 'postData' in the latest line here,
> otherwise I can see why this doesn't work...

Yes, my mistake. I cut/paste code from the function returning post and
assigning it to postData. So, yes I use the correct pointer.

> Well, if you make this test again using one post with curl and then one
with
> lynx that you say works, you can compare the perl outputs and check for
> differences.

Well, the output from Perl is that it gets the fields and their values. With
curl is says that it didn't receive anything.

> Can't you make your servlet let you know exactly when in the flow it stops
> understanding the input?

It's just at the very beginning when I get the values out of the request. If
I hit the servlet with the HTML POST from the HTML web page it just shows
the fields and their values. With curl it says that there are no
fields/values.

> Anybody has had any problems like this?

> Not that I know of. Others have used the multipart formpost feature
> successfully. I have too. I have test cases for it in the test suite
proving
> that it works at least partly.

Not sure if I'm using multipart formpost here. I can post the whole code if
you want. I'm getting desperate to get this fixed. Any help will be greatly
appreciated. I could put the servlet up on the Internet as well, so that you
can hit it with curl if you want.

> I can post the servlet code if you're interested.

> Personally, I'm a java cluebie and so I wouldn't really know what to do
with
> it.

Allright, well let me know otherwise.

Thanks, looking forward to getting to the bottom of this one,

-Anibal

-----Original Message-----
From: Daniel Stenberg [mailto:daniel_at_haxx.se]
Sent: Monday, June 03, 2002 19:54
To: Anibal Jodorcovsky
Cc: libcurl Mailing list
Subject: Re: HTTP POST not working with servlet

On Mon, 3 Jun 2002, Anibal Jodorcovsky wrote:

> I have redhat 6.2 with the latest curl curl-7.9.7-1.
>
> I have a servlet (written in Java) that accepts POST requests. I tried
> using libcurl and I get a response from the servlet as if it's not getting
> any of the form fields. I also used curl from the command line using the
> --form options and got the same error.

I take it you mean multi-part formposts then. This is not the same as a
regular post.

> However, if I build an HTML page with a FORM using POST then I get the
> right data back

You mean if you fill in the data with a browser and press submit? Are you
making that form a multi-part one then?

> I also tried hitting the servlet with lynx and it works fine as well. I
> ended up reverting to using GET with libcurl for the moment, but I want to
> get POST working.

It is possible that curl issues the posts somewhat differently. I can't tell
for sure.

> This is what I use in my code (but remember that curl itself doesn't seem
> to be pushing the data in the way the servlet is expecting it):
>
> std::map<std::string, std::string>::iterator it;
> for ( it = mFormFields.begin(); it != mFormFields.end(); it++ )
> {
> const int result = curl_formadd( &post, &last,
> CURLFORM_COPYNAME,
> (*it).first.c_str(),
> CURLFORM_COPYCONTENTS,
> (*it).second.c_str(),
> CURLFORM_END );
> if ( result != 0 )
> {
> return NULL;
> }
> }
>
> curl_easy_setopt( pCurl, CURLOPT_HTTPPOST, postData );

I guess you meant 'post' and not 'postData' in the latest line here,
otherwise I can see why this doesn't work...

> I created a 15-line Perl/CGI script that echoes back a POST request and
> curl works there. So, there has to be something in the request that the
> servlet is not liking and that Perl seems to not care.

Well, if you make this test again using one post with curl and then one with
lynx that you say works, you can compare the perl outputs and check for
differences.

Can't you make your servlet let you know exactly when in the flow it stops
understanding the input?

> Anybody has had any problems like this?

Not that I know of. Others have used the multipart formpost feature
successfully. I have too. I have test cases for it in the test suite proving
that it works at least partly.

> I can post the servlet code if you're interested.

Personally, I'm a java cluebie and so I wouldn't really know what to do with
it.

--
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
_______________________________________________________________
Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm
Received on 2002-06-04