Connecting Tech Pros Worldwide Help | Site Map

CURLOPT_POST ... doesn't!

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 02:15 PM
sundialsvc4
Guest
 
Posts: n/a
Default CURLOPT_POST ... doesn't!

(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, 02:15 PM
ZeldorBlat
Guest
 
Posts: n/a
Default 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, 02:15 PM
sundialsvc4
Guest
 
Posts: n/a
Default 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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.