http_post
| From: | Diana Castillo | Date: | Fri, 28 Feb 2003 08:31:30 +0000 |
| Subject: | http_post | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-137526@lists.php.net to get a copy of this message | ||
Hi , I am trying the following code but get no response from the server, can
someone tell me what I am doing wrong? thank you.
<?php
function http_post($server, $port, $url, $vars) {
// example:
// http_post(
// "www.fat.com",
// 80,
// "/weightloss.pl",
// array("name" => "obese bob", "age" => "20")
// );
$urlencoded = "";
while (list($key,$value) = each($vars))
$urlencoded.= urlencode($key) . "=" . urlencode($value) . "&";
$urlencoded = substr($urlencoded,0,-1);
$content_length = strlen($urlencoded);
$headers = "POST $url HTTP/1.1
Accept: text/plain, text/html, text/xml, image/gif, image/jpeg,
image/png, image/bmp
Accept-Charset: UTF-8
Accept-Language: en
Content-Length: $content_length
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
Host: $server
User-Agent: Panasonic-GAD67/1.0 UP.Browser/5.0.3.5 (GUI)
Connection: Keep-Alive
";
$fp = fsockopen($server, $port, $errno, $errstr);
if (!$fp) {
return false;
}
fputs($fp, $headers);
fputs($fp, $urlencoded);
$ret = "";
while (!feof($fp))
$ret.= fgets($fp, 1024);
fclose($fp);
return $ret;
}
$request="<barceloDS_requests><request type='destination list'
id='8'><language_code>ESP</language_code><agency><primary>888</primary><seco
ndary>88</secondary><detail>888</detail><branch>1</branch></agency></request
></barceloDS_requests>";
http_post("195.57.250.36",80,"/barceloDS/interface/xml/",array("xml"
=>$request));
?>