cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: HTTP POST not working with servlet

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Tue, 4 Jun 2002 01:54:24 +0200 (MET DST)

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