1. 使用 PHP 获得网页内容 GET方式
复制代码 代码如下:
<"/";
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp)
{
echo "$errstr ($errno)<br />\n";
return false;
}
else
{
$out = "GET $path HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n\r\n";
$ret = "";
fwrite($fp, $out);
while (!feof($fp))
{
$ret .= fgets($fp, 128);
}
fclose($fp);
}
return true;
}
"codetitle">复制代码 代码如下:
<"/";
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp)
{
echo "$errstr ($errno)<br />\n";
return false;
}
else
{
$out = "POST $path HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "Content-Length: ".strlen($data)."\r\n";
$out .= "Connection: Keep-Alive\r\n\r\n";
$out .= $data;
$ret = "";
fwrite($fp, $out);
while (!feof($fp))
{
$ret .= fgets($fp, 128);
}
fclose($fp);
}
return true;
}
"Connection: Keep-Alive\r\n\r\n";中的Keep-Alive改成Close
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“PHP中使用socket方式GET、POST数据实例”评论...