cURL / Mailing Lists / curl-library / Single Mail

curl-library

HTTP POST not working with servlet

From: Anibal Jodorcovsky <anibal_at_videotron.ca>
Date: Mon, 3 Jun 2002 19:36:10 -0400

Hi all,

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.

However, if I build an HTML page with a FORM using POST then I get the right
data back. 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.

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 );

my mFormFields is just an STL map containing the key-value pairs. I added a
printf in there and the data is correct. The servlet keeps complaining that
it's not getting the form fields.

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.

Anybody has had any problems like this?

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

Let me know,

thanks a lot,

-Anibal Jodorcovsky
 Montreal, Canada

_______________________________________________________________

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