下载安卓APP箭头
箭头给我发消息

客服QQ:3315713922

php学习_如何利用php语言模拟发送get请求?

作者:Comet     来源: 课课家 www.kokojia.com点击数:1184发布时间: 2015-06-26 09:59:29

标签: php学习php视频教程php入门教程

Web开发
如何利用php语言模拟发送get请求?课课家小编给学者们分享以下php学习的几种方法总结。
 
php学习模拟发送get请求
 
(1)php 通过 file_get_contents 模拟发送 get 请求

12$url='http://www.phpernote.com/php-function/654.html';
3$re=file_get_contents($url);
4print_r($re);

(2)php 通过 curl 模拟发送 get 请求

12$ch=curl_init('http://www.phpernote.com/php-function/651.html');
3curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
4curl_setopt($ch,CURLOPT_BINARYTRANSFER,true);
5$output=curl_exec($ch);
6$fh=fopen("out.html",'w');
7fwrite($fh,$output);
8fclose($fh);

(3)php 通过 fsocket 模拟发送 get 请求

0102function sock_get($url){ 
03    $info=parse_url($url);
04    $fp=fsockopen($info["host"],80,$errno,$errstr,3);
05    $head="GET ".$info['path']."?".$info["query"]." HTTP/1.0\r\n";
06    $head.="Host: ".$info['host']."\r\n";
07    $head.="\r\n";
08    $write=fputs($fp,$head);
09    while(!feof($fp)){ 
10        $line=fgets($fp);
11        echo $line."
";
12    }
13}
该函数的使用方法如下:$url='http://www.phpernote.com/jquery-effects/650.html?page=2';
echo "以下是GET方式的响应内容:
";
sock_get($url); 
更多PHP学习入门教程的相关知识,可登陆课课家网络教学平台进行查询观看视频教程!
赞(17)
踩(0)
分享到:
华为认证网络工程师 HCIE直播课视频教程