我用fsockeopen请求http,页面返回HTTP/1.1 400 Date: Tue, 03 Jul 2007 05:59:31 GMT Content-type: text/html Content-length: 110 Last-modified: Tue, 03 Jul 2007 05:59:31 GMT Pragma: no-cache Expires: 0 Cache-Control: no-cache Connection: Keep-Alive Bad Request ,这是什么原因
$password=$_POST['password'];
$host="www.teamsun.com.cn:88";
$service_uri="/login.msc";
$query_string="user=$username&password=$password&mode=submit";
$http_request="POST ". $service_uri ." HTTP/1.1\r\n";
$http_request.="Host:$host\r\n";
$http_request.="Content-Type: application/x-www-form-urlencoded\r\n";
$http_request.="Accept-Encoding: gzip, deflate";
$http_request.="Content_Length:".strlen($query_string)."\r\n";
$http_request.="Connection: Keep-Alive\r\n\r\n";
$http_request.="Cache-Control: no-cache";
$fs = fsockopen($host,88);
if (!is_resource($fs)){
echo "trackback_send: Couldn't connect to $host,Port 88";
return false;
}
fwrite($fs, $http_request);
while(!feof($fs))
{
$response.=fread($fs,8192);
}
fclose($fs);
echo $response;
楼上的我是这样请求的
try:
============
1.-----------------------------------
$host="www.teamsun.com.cn:88";//----->改为$host="www.teamsun.com.cn";2.-----------------------------------
$http_request="POST ". $service_uri ." HTTP/1.1\r\n";
$http_request.="Host:$host\r\n";
$http_request.="Content-Type: application/x-www-form-urlencoded\r\n";
$http_request.="Accept-Encoding: gzip, deflate";
$http_request.="Content_Length:".strlen($query_string)."\r\n";
$http_request.="Connection: Keep-Alive\r\n\r\n";
//加一行
$http_request.=$query_string."\r\n";//添加post字符串
$http_request.="Cache-Control: no-cache";
改为
Content-Length:
$http_request.="Connection: Keep-Alive\r\n\r\n";
改为
$http_request.="Connection: Keep-Alive\r\n";
$http_request.="Cache-Control: no-cache";
改为
$http_request.="Cache-Control: no-cache\r\n\r\n";
$fs = fsockopen($host,88); 前面添加$http_request .= $query_string."\r\n\r\n";问题比较多.建议你先去看看HTTP协议或者,你先去抓个包.然后按包写....
=>
$http_request.="Connection: close\r\n\r\n";
还是出现同样的错误,我用iris抓的包
Host:www.teamsun.com.cn
Content-Type: application/x-www-form-urlencoded
Accept-Encodeing: gzip, deflate
Content-Length: 35
Connection: Keep-Alive
Cache-Control: no-cacheuser=test&password=test&mode=submit
php编程我是个新手,抓的包基本上和你写的差不多,referer,accept,Accept-Language这些参数还要写上吗,不是必须的吧
不会出400错误.只会出302 因为用户名密码不对.
按照你的写法,我显示不出任何值
我已经搞定了,不过我想问你下如何取得反应回来的头部中的loaction的值