curl-and-php
Re: POST problem
From: Alan Storm <gliff_at_rochester.rr.com>
Date: Sun, 30 May 2004 23:32:25 -0400
Date: Sun, 30 May 2004 23:32:25 -0400
On 5/30/04, Stijn De Maesschalck typed
>If you want, you can take a look on
>http://info.czar.be/webmail.php. I've put the HTML code
>there along with the PHP code I'm using.
Your POST data isn't being sent.
CURLOPT_POSTFIELDS expects a URL encoded query string, not an
associative array. Try the code listed below my sig (changes to your
code marked in comments)
If your webmail app. requires cookies, you're going to need to muck
about with those options as well.
-- Alan Storm http://www.gliff.org +------------------------------------------------------------+ <?php //this function is passed an array, and returns a //url encoded query string. function encodeQueryString($array){ if(!is_array($array)){ die("Encode Post Array expects an array"); } $retValue = ''; for(reset($array);$key=key($array);next($array)){ $retValue .= $key."=".urlencode($array[$key])."&"; } //zap last & $retValue = substr($retValue, 0, -1); return $retValue; } ?> <?php $postdata['imapuser']="test"; $postdata['pass']="12345"; $postdata['actionid']="105"; $postdata['url']="http://webmail.info.czar.be/horde/login.php"; $postdata['mailbox']="INBOX"; $postdata['port']="143"; $postdata['server']="localhost"; $postdata['namespace']=""; $postdata['maildomain']="info.czar.be"; $postdata['protocol']="imap/notls"; $postdata['realm']="info.czar.be"; $postdata['folders']="INBOX."; $postdata['submit']="open+webmail"; //pass associative array to function that will //create an encoded query string $postdata = encodeQueryString($postdata); $ch = curl_init(); curl_setopt($ch, CURLOPT_VERBOSE,1); curl_setopt($ch, CURLOPT_URL, "http://webmail.info.czar.be/horde/login.php"); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // execute a POST request $result = curl_exec ($ch); curl_close($ch); print($result); ?> +------------------------------------------------------------+Received on 2004-05-31