利用fsocket模拟GET和POST请求_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了利用fsocket模拟GET和POST请求_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1705字,纯文字阅读大概需要3分钟。
内容图文
[php]//fsocket模拟get提交
$gurl = "http://localhost/php/t.php?uu=gggggg";
//print_r(parse_url($gurl));
echo "以下是GET方式的响应内容:
";
sock_get($gurl);
function sock_get($url)
{
$info = parse_url($url);
$fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
$head = "GET ".$info['path']."?".$info["query"]." HTTP/1.0\r\n";
$head .= "Host: ".$info['host']."\r\n";
$head .= "\r\n";
$write = fputs($fp, $head);
while (!feof($fp))
{
$line = fgets($fp);
echo $line."
";
}
}
//fsocket模拟post提交
$purl = "http://localhost/php/t.php";
echo "以下是POST方式的响应内容:
";
sock_post($purl,"uu=rrrrrrrrrrrr&&kk=mmmmmm");
function sock_post($url, $query)
{
$info = parse_url($url);
$fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
$head = "POST ".$info['path']." HTTP/1.0\r\n";
$head .= "Host: ".$info['host']."\r\n";
$head .= "Referer: http://".$info['host'].$info['path']."\r\n";
$head .= "Content-type: application/x-www-form-urlencoded\r\n";
$head .= "Content-Length: ".strlen(trim($query))."\r\n";
$head .= "\r\n";
$head .= trim($query);
$write = fputs($fp, $head);
while (!feof($fp))
{
$line = fgets($fp);
echo $line."
";
}
}
?>
请求的响应页面t.php
[php]
if(isset($_GET['uu'])){
echo 't.php中$_GET["uu"]的值是:'.$_GET['uu']."
";
}
if(isset($_POST['uu'])){
echo 't.php中$_POST的值是:
';
print_r($_POST);
}
?>
以下为运行结果:
以下为Firebug的查看结果:
作者:Fanteathy
http://www.bkjia.com/PHPjc/478114.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478114.htmlTechArticle[php] ?php //fsocket模拟get提交 $gurl = http://localhost/php/t.php?uu=gggggg; //print_r(parse_url($gurl)); echo 以下是GET方式的响应内容:br; sock_get($gurl); functio...
内容总结
以上是互联网集市为您收集整理的利用fsocket模拟GET和POST请求_PHP教程全部内容,希望文章能够帮你解决利用fsocket模拟GET和POST请求_PHP教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。