PHP发送post数据函数
时间:2006-02-17 来源:ashchen
原创来自cosrc.com
http://www.cosrc.cn
http://www.cosrc.net
用法例:
post('127.0.0.1','/test.php','a=asdfsdfsdf&b=kjhdsfkjhsdkjf');
function post($host,$path,$data)
{
$fp = fsockopen($host, 80);
fputs($fp,"POST $path HTTP/1.1\r\n");
fputs($fp,"Host: $host\r\n");
fputs($fp,"Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp,"Content-length: " . strlen($data) . "\r\n");
fputs($fp, "User-Agent: MSIE\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);
$buf='';
while (!feof($fp)) {
$buf .= fgets($fp,128);
}
fclose($fp);
return $buf;
}
相关阅读 更多 +