josh803316 has asked for the wisdom of the Perl Monks concerning the following question:

I'm having trouble getting my curl to post correctly with WWW::Curl, or at least having trouble mimicking the -d command line option.
The following shows the command line example that works using -k to turn off cert checking and -d to send the post arguments
(Command Line Example that works) shell#curl -d 'level=2&pass=password&hsam_timeout=20' -k https://1.1.1 +.1/auth AUTH: OK SESSION: 4221231856 (EXAMPLE TEST with module distro t/new/06http-post.t) $curl->setopt( CURLOPT_URL, $ENV{CURL_TEST_URL} ); $curl->setopt( CURLOPT_READFUNCTION, \&read_callback ); $curl->setopt( CURLOPT_INFILESIZE, $max ); $curl->setopt( CURLOPT_UPLOAD, 1 ); $curl->setopt( CURLOPT_CUSTOMREQUEST, 'POST' ); my $code = $curl->perform; (My code that also turns off the ssl check) $curl->setopt( CURLOPT_URL,'https://1.1.1.1/auth?level=2&pass=password +&hsam_timeout=20' ); $curl->setopt( CURLOPT_READFUNCTION, \&read_callback ); $curl->setopt( CURLOPT_INFILESIZE, $max ); $curl->setopt( CURLOPT_UPLOAD, 1 ); $curl->setopt( CURLOPT_CUSTOMREQUEST, 'POST' ); $curl->setopt(CURLOPT_SSL_VERIFYPEER,0); $curl->setopt(CURLOPT_SSL_VERIFYHOST,0); my $code = $curl->perform;
Any ideas if I am doing this wrong? Do I need to use the following options instead?
$curl->setopt( CURLOPT_POST, 1); $curl->setopt( CURLOPT_POSTFIELDSIZE, 100); $curl->setopt( CURLOPT_POSTFIELDS, "level=2&pass=password&hsam_timeout +=20");

Here is the error I'm getting:
> POST /auth?level=2&pass=password&hsam_timeout=20 HTTP/1.1 Host: 10.2.200.101 Accept: */* Content-Length: 100 Expect: 100-continue < HTTP/1.1 417 Expectation Failed < Connection: close < Content-Length: 0 < Date: Tue, 19 May 2009 02:16:25 GMT < Server: httpd < * Closing connection #0

Replies are listed 'Best First'.
Re: Correct way to POST with Perl Curl?
by Anonymous Monk on May 19, 2009 at 03:56 UTC
      Here is the full attempt with mode verbose
      * About to connect() to 1.1.1.1 port 443 (#0) * Trying 1.1.1.1... * connected * Connected to 1.1.1.1 (1.1.1.1) port 443 (#0) * CAfile: /certs/ca-bundle.crt CApath: none * Issuer certificate is invalid: 'E=support' * SSL certificate verify ok. * SSL connection using SSL_RSA_WITH_RC4_128_MD5 * Server certificate: * subject: * start date: May 08 04:35:59 2009 GMT * expire date: May 07 04:35:59 2014 GMT * common name: 1.1.1.1 * > POST /auth?level=2&pass=password&hsam_timeout=20 HTTP/1.1 Host: 1.1.1.1 Accept: */* Content-Length: 1000 Expect: 100-continue < HTTP/1.1 417 Expectation Failed < Connection: close < Content-Length: 0 < Date: Tue, 19 May 2009 04:35:22 GMT < Server: httpd < * Closing connection #0
        Well, here is what ended up working for me, perhaps it can help somebody else down the line:
        $curl->setopt( CURLOPT_POSTFIELDS, "$string" ); $curl->setopt( CURLOPT_POSTFIELDSIZE, $length ); $curl->setopt( CURLOPT_POST, 1 ); $curl->setopt( CURLOPT_CONNECTTIMEOUT,8);