这篇文章主要介绍了php中使用socket方式get、post数据实例,本文分别给出get方式和post方式的代码实例,需要的朋友可以参考下
1. 使用 PHP 获得网页内容 GET方式
代码如下:
\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;
}
?>2. 使用 PHP 向页面 POST 数据
说明:用途:程序员、美工、中小型科技公司接单建站使用1.将此文件夹下的文件传入根目录下2.数据库文件:company.sql3.把数据库文件导入数据库4.修改数据库链接信息(用户名、密码,数据库名):/inc/dabase_mysql.php5.超级帐号webmaster 密码:123456 后台管理目录/cdguanli6.后台栏目配置和前台插件的调用方式,请见官网教程。7.前台插件调用示例相比
代码如下:
\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;
}
?>如果post报错,把$out .= "Connection: Keep-Alive\r\n\r\n";中的Keep-Alive改成Close










