1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > php 模拟 https请求头 php 模拟 http 请求

php 模拟 https请求头 php 模拟 http 请求

时间:2021-04-03 07:21:51

相关推荐

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";

//发送

fwrite($fp, $out);

//提取结果

while(!feof($fp)){

echo fgets($fp);

}

?>

post

//创建连接

$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"; //请求头和请求体之间要有两个\r\n

//请求体

$http.="email=xiaohigh@&username=admin\r\n";

//发送

fwrite($fp, $http);

//提取结果

while(!feof($fp)){

echo fgets($fp);

}```

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。