我用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 ,这是什么原因

解决方案 »

  1.   

    $username=$_POST['username'];
      $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;
    楼上的我是这样请求的
      

  2.   

    你好象只发送了  $http_request而 $query_string 什么时候送给服务器的???
      

  3.   


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

  4.   

    Content_Length:
    改为 
    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协议或者,你先去抓个包.然后按包写....
      

  5.   

    $http_request.="Connection: Keep-Alive\r\n\r\n";
       =>
    $http_request.="Connection: close\r\n\r\n";
      

  6.   

    to:mrshelly(Shelly)
    还是出现同样的错误,我用iris抓的包
      

  7.   

    POST /login.msc HTTP/1.1
    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
      

  8.   

    to:mrshelly(Shelly)
    php编程我是个新手,抓的包基本上和你写的差不多,referer,accept,Accept-Language这些参数还要写上吗,不是必须的吧
      

  9.   

    你严格按照抓的包写,一般是不会有大的问题....你把我的包复制...开个TELNET 到 88 端口.粘贴进去. 就可以看到了...
    不会出400错误.只会出302  因为用户名密码不对.
      

  10.   

    to:mrshelly(Shelly)
    按照你的写法,我显示不出任何值
      

  11.   

    to:mrshelly(Shelly)
    我已经搞定了,不过我想问你下如何取得反应回来的头部中的loaction的值