CURLOPT_POST ... doesn't!

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
(Environment: Linux)
curl 7.10.6 (i386-redhat-linux-gnu) libcurl/7.10.6 OpenSSL/0.9.7a ipv6
Protocols: ftp gopher telnet dict ldap http file https ftps
Features: IPv6 SSL libz NTLM
PHP 5.0.2 (cgi) (built: Jul 10 2005 15:41:02)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.2, Copyright (c) 1998-2004 Zend Technologies

I can use CURL to retrieve a web-page but when I try to use POST, it
doesn't seem to actually post anything.  The code is:

$ch  = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER,     True);
curl_setopt ($ch, CURLOPT_USERAGENT,         $config['user_agent']);
curl_setopt ($ch, CURLOPT_HEADER,         True);
curl_setopt ($ch, CURLOPT_VERBOSE,        True);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION,    True);
global $errfile;
curl_setopt ($ch, CURLOPT_STDERR,        $errfile);
curl_setopt ($ch, CURLOPT_FAILONERROR,        True);
// If we have any cookies, send them with each request.
if (retrieve_cookies($cook))
    curl_setopt($ch, CURLOPT_COOKIE, $cook);
// If the caller provided any POST variables, send them... properly
if (!empty($postvars)) {
    if (is_array($postvars)) {
        $post  = '';
        $amper = '';
        foreach ($postvars as $p=>$v) {
            $post .= $amper . urlencode($p) . '=' . urlencode($v);
            $amper = '&';
    } else $post = $postvars;
echo ">>Sending POST vars: '$post'\n";
// e.g. "username=goofus&password=gallant"
    curl_setopt ($ch, CURL_POST,       True);
    curl_setopt ($ch, CURL_POSTFIELDS, $post);
    $data = curl_exec($ch);

Script debugging output confirms that "$post" does have a
properly-formatted string in it, e.g.
"username=goofus&password=gallant"  And that CURL_POSTFIELDS is indeed
being called.  But I see no indication that this data is making it to
the server.

The (sanitized...) VERBOSE logfile is:
* About to connect() to
* Connected to ( port 80
Quoted text here. Click to load it
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*

< HTTP/1.1 200 OK
< Date: ...
< Server: Apache ...
< Connection: close
< Transfer-Encoding: chunked
< Content-Type: text/html
* Closing connection #0

Re: CURLOPT_POST ... doesn't!

Rather than $post being a string, try making it an array:

$post = array('username' => 'goofus', 'password' => 'gallant')

Re: CURLOPT_POST ... doesn't!

Okay, I tried that, and unfortunately it had no effect.

Also... just to make sure, I retrieved the latest source-code, compiled
it from source, re-built PHP the same way (confirming that PHP does
reference the new library via 'php --info')... nothing changed.
curl 7.14.0 (i686-pc-linux-gnu) libcurl/7.14.0 OpenSSL/0.9.7a
Protocols: ftp gopher telnet dict ldap http file https ftps
Features: Largefile NTLM SSL libz

I don't know how to easily tell /exactly/ what the two systems are
saying to each other (in the Linux environment), although I suppose
that will be the next step.  (Anyone tell me how that's done?)

I'm not enough of an HTTP-guru to be able to tell whether the verbose
logfile (from the original post) does, or does not, tell me if the
post-data is being sent.

Site Timeline