tencent-模拟请求头

来源:互联网 发布:ptc软件收费模式 编辑:程序博客网 时间:2024/05/16 11:09

最近...不多说,说多了都是泪,直接上问题和答案:

不使用CURL函数分别写出client.phpserver.php两个文件内容.
client.php模拟浏览器客户端向server.php发送如下HTTP数据包.
server.php向client.php输出md5(username+password)后的结果
POST http://localhost/server.php HTTP/1.1
Accept: image/jpeg, image/gif, image/pjpeg, */*
User-Agent: Mozilla/4.0
Content-Type: application/x-www-form-urlencoded
Host: localhost
Content-Length: 34
Connection: Keep-Alive
Cookie: HOSUPPORT=1; UBI=fi_Pnc;
username=a&password=c&action=login
相关资料:http://www.cnblogs.com/zhenbianshu/p/4929767.html
可运行代码:http://blog.csdn.net/debug_zhang/article/details/52179270

//假设host:localhost//Client.php文件内容为:$url = "http://localhost/server.php";$fp = fsockopen ( "localhost", 80, $errno, $errstr, 3 );$head = "POST /server.php HTTP/1.0\r\n";$head .= "Accept: image/jpeg, image/gif, image/pjpeg, */*\r\n";$head .= "User-Agent: Mozilla/4.0\r\n";$head .= "Content-type: application/x-www-form-urlencoded\r\n";$head .= "Host: localhost\r\n";$head .= "Content-Length: 34\r\n";$head .= "Connection: Keep-Alive\r\n";$head .= "Cookie: HOSUPPORT=1; UBI=fi_Pnc;\r\n";$head .= "\r\n"; $head .= trim ( "username=a&password=c&action=login" );$write = fputs ( $fp, $head );fgets ( $fp );while ( ! feof ( $fp ) ) {$line = fgets ( $fp );echo $line . "<br>";} //Server.php内容为:echo md5($_POST['username'].$_POST['password']);












 

0 0