Connecting Tech Pros Worldwide Help | Site Map

CURLOPT_POST ... doesn't!

  #1  
Old July 17th, 2005, 03:15 PM
sundialsvc4
Guest
 
Posts: n/a
(Environment: Linux)
curl 7.10.6 (i386-redhat-linux-gnu) libcurl/7.10.6 OpenSSL/0.9.7a ipv6
zlib/1.1.4
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
formatted.
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 xxx.yyy.com:80
* Connected to aaa.bbb.net (11.22.33.44) port 80[color=blue]
> GET /index.cgi HTTP/1.1[/color]
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Host: xxx.yyy.com
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
==================================

  #2  
Old July 17th, 2005, 03:15 PM
ZeldorBlat
Guest
 
Posts: n/a

re: CURLOPT_POST ... doesn't!


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

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

  #3  
Old July 17th, 2005, 03:15 PM
sundialsvc4
Guest
 
Posts: n/a

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
zlib/1.1.4
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.

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Orkut Grabber Suhas Dhoke answers 1 October 30th, 2008 06:15 AM
posting with cURL problem zorro answers 4 December 29th, 2006 09:25 PM
godaddy login via curl php script nfhm2k@gmail.com answers 0 July 31st, 2006 10:25 PM
cURL doesn't get URL with required cookie Phil Powell answers 0 July 17th, 2005 07:57 AM