php 模拟 https请求头,php 模拟 http 请求
get
//建立連接
$fp=fsockopen("localhost",80,$errno,$errstr,30);
if(!$fp){
echo "$errstr $errno"die;
}
//請求行
$out="GET /myproject/html/server.php?username=admin&page=12 HTTP/1.1\r\n";
//請求頭
$out.="Host: localhost\r\n";
$out.="Connection: Close\r\n\r\n";
//發(fā)送
fwrite($fp, $out);
//提取結(jié)果
while(!feof($fp)){
echo fgets($fp);
}
?>
post
//創(chuàng)建連接
$fp=fsockopen("localhost",80,$errno,$errstr,10);
//判斷
if(!$fp){
echo "$errstr $errno";die;
}
$http="";
//請求行
$http.="POST /myproject/html/server.php HTTP/1.1\r\n";
//請求頭
$http.="Host: localhsot\r\n";
$http.="Connection: Close\r\n";
$http.="Cookie: username=admin;uid=123456\r\n";
$http.="User-agent: firefox-chrome-safari-ios-android\r\n";
$http.="Content-type: application/x-www-form-urlencoded\r\n";
$http.="content-length: 37\r\n\r\n"; //請求頭和請求體之間要有兩個(gè)\r\n
//請求體
$http.="email=xiaohigh@163.com&username=admin\r\n";
//發(fā)送
fwrite($fp, $http);
//提取結(jié)果
while(!feof($fp)){
echo fgets($fp);
}```
總結(jié)
以上是生活随笔為你收集整理的php 模拟 https请求头,php 模拟 http 请求的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php中mysqli_query,在PH
- 下一篇: matlab7.0 win7 64,安装