Needed: PHP Guru
I'm working on the first CouchDb demos and doing them in PHP. I chose PHP because it's supposed to be simple and easy.
Is anyone out available to field some (probably) easy PHP questions? My current frustration right now is trying to get the HTTP library working, everything appears to be in place but I can't call the library. The CURL library, my first choice for a HTTP client library, is working but apparently can't do simple POSTs without multipart-form encoding it.
Please help me before I hurt something.
Update:
I figured out the problem with HTTP lib. I was editing the wrong php.ini file. I'd still like to know how to POST arbitrary content-types with the CURL lib, but I fear it's not possible.
Posted August 9, 2006 9:43 PM
Comments
Here is a POST example from my article( http://www-128.ibm.com/developerworks/lotus/library/domino-php/ ). It's not using CURL but maybe can help you anyway. The example posts login credentials to Domino server and shows received session cookie.
$req="username=john+doe&password=john123";
$opts = array(
"http"=>array(
"method"=>"POST",
"content" => $req,
"header"=>"Accept-language: en\r\n" .
"User-Agent: Mozilla/4.0 (compatible;
MSIE 6.0; Windows NT 5.1)\r\n"
)
);
$context = stream_context_create($opts);
if (!($fp = fopen("http://server.com/maildb.nsf?login",
"r", false, $context))) {
die("Could not open login URL");
}
$meta = stream_get_meta_data($fp);
for ($j = 0; isset($meta["wrapper_data"][$j]); $j++)
{
if (strstr(strtolower($meta["wrapper_data"][$j]), 'set-cookie'))
{
$cookie = substr($meta["wrapper_data"][$j],12);
break;
}
}
fclose($fp);
$_SESSION["DominoCookie"]=$cookie;
Andrei Kouvchinnikov, August 9, 2006 10:16 PM
We're using this to post XML data to a server, hope it helps:
// generate request
$contentLength = strlen($requestContent);
$requestHeader = "POST " . $parsedUrl['path'] . " HTTP/1.0\r\n";
$requestHeader .= "Content-Type: text/xml\r\n";
$requestHeader .= "Content-Length: " . $contentLength . "\r\n";
$requestHeader .= "Connection: close\r\n";
$requestHeader .= "\r\n";
$request = $requestHeader . $requestContent;
// issue request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $parsedUrl['scheme'] . "://" . $parsedUrl['host'] . ":" . $parsedUrl['port'] . "/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request);
$replyData = curl_exec($ch);
Maarten Sander, August 12, 2006 3:23 AM
Thanks Maarten. That's just what I was looking for.
Damien, August 12, 2006 9:00 PM
Post a comment