cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Problem: posting a file upload to a https server

From: Keith Hui <keithhui_at_accessv.com>
Date: Fri, 17 May 2002 16:02:53 -0400

Hi Guys,

First post and I already needed help.

I am developing a command-line PHP script to link the customer record system
for an ISP to a third party email filtering service that does everything
through form posts to a SSL-secured web site. I got most of the form posts
working but it stuck at the point where I need to upload a file to the
remote end by HTTP post (yes, RFC1867).

My setup is PHP 4.1.2, curl 7.9.7 (same problem with 7.9.6 too), openssl
0.9.6b.

My code is as follows:

---------

print "-- Exec upload --\n";
// Prep the upload
$ch = curl_init("https://login.postini.com/exec/Admin?action=change_batch");
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01;
Windows NT 5.0)");
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
// Needs to retain and pass back some cookies. This part is OK.
curl_setopt($ch,CURLOPT_COOKIEFILE,$cookiejar);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$fields = array("batchmode"=>"Submit job");
$fields[realanswer]=$realanswer;
$fields["answer"]=$realanswer;
$fields[batchFile]="@$batchfile";

curl_setopt($ch,CURLOPT_POSTFIELDS,$fields);
// Debug options
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch,CURLOPT_VERBOSE,1);
curl_setopt($ch,CURLOPT_FORBID_REUSE,1); // Tried with and without this
curl_setopt($ch,CURLOPT_LOW_SPEED_LIMIT,1);
curl_setopt($ch,CURLOPT_LOW_SPEED_TIME,60);
$retval = curl_exec($ch);
curl_close($ch);

print "-- Upload result --\n\n";
print $retval;

$q=strstr($retval,"Executed"); // Some expected result from the server
if ($q===false)
{
    print "Upload did not succeed\n";
} else print "Upload successful\n";

---------

$batchfile is a text file with commands to be uploaded.

My program would run to curl_exec() and not return from it. If I set
LOW_SPEED_TIME and LOW_SPEED_LIMIT, it will return after LOW_SPEED_TIME (60
seconds in my code) with an error and $retval empty (or being false).

By enabling various debugging options in the PHP curl module I knew that the
curl request is executed correctly (and the server returned the expected
response). When I checked with the server myself, the changes written in
$batchfile is executed.

If I set RETURNTRANSFER to 0, I'll see the server's entire response.

I have tried everything on the book, for both PHP and curl, and still cannot
get it to recognize that the one and only response the server will send has
been sent, and return with it.

Do I have to tell curl to make a custom request to make this work?

Appreciate all help.

Keith

_______________________________________________________________

Hundreds of nodes, one monster rendering program.
Now that’s a super model! Visit http://clustering.foundries.sf.net/
Received on 2002-05-17