标签:get请求 运用 etop method 客户端 win top header array
telnet模拟http请求:
cmd进去以后输入:telnet 127.0.0.1 80 回车(如果程序用不了,那么进去控制面板->程序和功能->打开或关闭windows功能,勾选telnet客户端即可),然后按下ctrl+],回车就可以了
-------------------------
GET请求:
GET http://localhost/test.php HTTP/1.1
HOST:localhost
注意要多一行空格
------------------------
接下来是POST请求:
POST http://localhost/test.php HTTP/1.1
HOST:localhost
Content-type:application/x-www-form-urlencoded
act=query&name=zzz
--------------------------
file_get_contents模拟表单提交(这里是post提交)
<?php $postData = array( ‘title‘=> ‘我是file_get_contents的构造数据‘, ‘content‘=> ‘我是file_get_contents的构造数据内容‘, ‘publish‘=> ‘发布‘, ); $postData = http_build_query($postData); $opts = array( ‘http‘=>array( ‘method‘=>"POST", ‘header‘=>"Host:localhost\r\n" . "Content-type:application/x-www-form-urlencoded\r\n" . "Content-length:" . strlen($postData) . "\r\n", ‘content‘=>$postData, ) ); $context = stream_context_create($opts); file_get_contents("http://localhost/http/index.php",false,$context);
fopen模拟表单提交
<?php $postData = array( ‘title‘=> ‘我是fopen的构造数据‘, ‘content‘=> ‘我是fopen的构造数据内容‘, ‘publish‘=> ‘发布‘, ); $postData = http_build_query($postData); $opts = array( ‘http‘=>array( ‘method‘=>"POST", ‘header‘=>"Host:localhost\r\n" . "Content-type:application/x-www-form-urlencoded\r\n" . "Content-length:" . strlen($postData) . "\r\n", ‘content‘=>$postData, ) ); $context = stream_context_create($opts); $fp = fopen("http://localhost/http/index.php","r",false,$context); $fclose($fp);
curl方式模拟表单提交
$url = "http://localhost/http/index.php"; $postData = array( ‘title‘=> ‘我是curl的构造数据‘, ‘content‘=> ‘我是curl的构造数据内容‘, ‘publish‘=> ‘发布‘, ); //初始化一个curl会话 $ch = curl_init(); //设置相应的会话选项 curl_setopt($ch, CURLOPT_URL, $url);//设置提交网址 curl_setopt($ch, CURLOPT_POST, 1); //设置提交方式,值为1表示肯定 curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); //设置提交数据 $output = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //提交成功后把数据返回成字符串 //执行 curl_exec($ch); //关闭 curl_close($ch); echo $output;
编辑未完成,持续更新中...
标签:get请求 运用 etop method 客户端 win top header array
原文地址:http://www.cnblogs.com/hopelooking/p/7662438.html