不报错啊,但是test1.php执行结果是abc ,
事实上要是post过去的吧应该是array("a"=>'aaa',"b"=>'bbb'); ok,aaa吧

解决方案 »

  1.   

    a1=aaa&a2=bbbHTTP/1.1 200 OK Server: Microsoft-IIS/5.0 Date: Mon, 12 Sep 2005 08:47:42 GMT Connection: close Content-type: text/html X-Powered-By: PHP/4.3.11 Array ( ) 123
    这是程序运行结果,
      

  2.   

    对调
    $header .= "Connection:close \r\n\r\n";
    $header .= $params."\r\n";

    $header .= $params."\r\n";
    $header .= "Connection:close \r\n\r\n";你都close了,还怎么发数据?
      

  3.   

    再发送的数据不属于header吧换成 xuzuning(唠叨)老大的方法结果还是一样啊,还是收不到数据
      

  4.   

    不可能的,这是测试例,与你的没有什么不同
    $fp = fsockopen($url, 80, $errno, $errstr, 30);
    if (!$fp) {
        echo "$errstr ($errno)<br />\n";
    } else {
    $str = 'a=1&b=2';
        $out = "POST /post_test.php HTTP/1.1\r\n";
        $out .= "Host: $url\r\n";
        $out .= "Content-Length: ". strlen($str) . "\r\n"; 
        $out .= "Content-Type: application/x-www-form-urlencoded\r\n\r\n";
        $out .= $str."\r\n\r\n";
        $out .= "Connection: Close\r\n\r\n";    fwrite($fp, $out);
        while (!feof($fp)) {
            echo fgets($fp, 128);
        }
        fclose($fp);
    }post_test.php
    <?php
    print_r($_POST);
    ?>HTTP/1.1 200 OK
    Connection: close
    Date: Mon, 12 Sep 2005 09:18:42 GMT
    Content-type: text/html
    X-Powered-By: PHP/5.0.3Array
    (
        [a] => 1
        [b] => 2
    )
      

  5.   

    $header .= "Content-Lengh:$len\r\n";改成:$header .= "Content-Length:$len\r\n";
      

  6.   

    急啊,老大,帮忙看看,为什么 
    test1.php能正确运行,而test2.php运行提示参数不正确呢,
    ----------------------------------------------
    test1.php
    -------------------------------------------
    <?php
    set_time_limit(0);
    $url = "http://www.fotocasa.es/busq/resultados.aspx?idTipoInmueble=2&idTipoOferta=2&idProvincia=27&idZona1=0&idZona2=0&idBarrio=0&idOtrasZonas=0&IdPoblacion=0&idDistrito=-2&Precio=0&Superficie=0&nHabitaciones=0&idTipoVivienda=0&x=50&y=9";
    $file = file_get_contents($url);
    //取__VIEWSTATE
    if(preg_match_all("|__VIEWSTATE\'?\"?\s+value\s*=\s*\"?\"(.+?)\"|is",$file,$viewStates))
    {
    $viewState = $viewStates[1][0];
    }
    $tmp = "dgrdResultados1\$_ctl54\$_ctl2";
    $eventTarget = str_replace("$",":",$tmp);
    $eventArgument = "";
    ?>
    <form name="Form1" action="http://www.fotocasa.es/busq/resultados.aspx?idTipoInmueble=2&idTipoOferta=2&idProvincia=27&idZona1=0&idZona2=0&idBarrio=0&idOtrasZonas=0&IdPoblacion=0&idDistrito=-2&Precio=0&Superficie=0&nHabitaciones=0&idTipoVivienda=0&x=50&y=9" method="post">
    <input type="hidden" name="__EVENTTARGET" value="<?=$eventTarget?>" >
    <input type="hidden" name="__EVENTARGUMENT" value="<?=$eventArgumen?>">
    <input type="hidden" name="__VIEWSTATE" value="<?=$viewState?>" />
    <input type="button" name="button5" value="下一页" onClick="FormSubmit()">
    </form>
    <script language="javascript" type="text/javascript">
    function FormSubmit() {
    var theform;
    if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
    theform = document.Form1;
    }
    else 
    {
    theform = document.forms["Form1"];
    }
    theform.submit();
    }
    // -->
    </script>
    ------------------------------------------------------
    test2.php
    -------------------------------------------------------
    <?php
    set_time_limit(0);
    $url = "http://www.fotocasa.es/busq/resultados.aspx?idTipoInmueble=2&idTipoOferta=2&idProvincia=27&idZona1=0&idZona2=0&idBarrio=0&idOtrasZonas=0&IdPoblacion=0&idDistrito=-2&Precio=0&Superficie=0&nHabitaciones=0&idTipoVivienda=0&x=50&y=9";
    $file = file_get_contents($url);//取__VIEWSTATE
    if(preg_match_all("|__VIEWSTATE\'?\"?\s+value\s*=\s*\"?\"(.+?)\"|is",$file,$viewStates))
    {
    $viewState = $viewStates[1][0];
    }//取得总页数
    if(preg_match_all("|dgrdResultados1[$]_ctl54[$]_ctl([0-9]+)|is",$file,$pages))
    {
    $count = count($pages[1]);
    $count--;
    $totalPage = $pages[1][$count];
    $totalPage++;
    }
    $url = "www.fotocasa.es";
    $fp = fsockopen($url,80,&$errno,&$errstr,30);
    if(!$fp)
    {
    echo $errno.$errstr;
    die();
    }
    else
    {
    //第一页数据是用get 取得的 上面的file_get_content所取得的
    $page = 2;
    $tmp = "dgrdResultados1\$_ctl54\$_ctl2";
    $eventTarget = str_replace("$",":",$tmp);
    $eventArgument = "";

    //参数附加
    $file = "";
    $str = "__EVENTTARGET=$eventTarget&__EVENTARGUMENT=$eventArgument&__VIEWSTATE=$viewState";
    $len = strlen($str); 

    $header = "POST http://www.fotocasa.es/busq/resultados.aspx?idTipoInmueble=2&idTipoOferta=2&idProvincia=27&idZona1=0&idZona2=0&idBarrio=0&idOtrasZonas=0&IdPoblacion=0&idDistrito=-2&Precio=0&Superficie=0&nHabitaciones=0&idTipoVivienda=0&x=50&y=9  HTTP/1.1\r\n";  
    //$header = "POST /php/spy/6.php HTTP/1.1\r\n";
    $header .= "Host:$url\r\n";
    $header .= "Content-Length:$len\r\n";
    $header .= "Content-type: application/x-www-form-urlencoded\r\n\r\n"; 
    $header .= $str."\r\n";         
    $header .= "Connection:Close\r\n\r\n";
    fputs($fp,$header);
    while(!feof($fp))
    {
    $file .= fgets($fp, 4096);
    }
    echo "fileLength:".strlen($file);
    echo "<br>";
    echo "<br>";
    echo $file;
    }
    ?>---------------------------------------------------------------------
    //test2.php运行结果
    ---------------------------------------------------------------------
    fileLength:866HTTP/1.1 100 Continue Server: Microsoft-IIS/5.0 Date: Tue, 13 Sep 2005 01:47:16 GMT X-Powered-By: ASP.NET HTTP/1.1 302 Found Server: Microsoft-IIS/5.0 Date: Tue, 13 Sep 2005 01:47:19 GMT X-Powered-By: ASP.NET X-AspNet-Version: 1.1.4322 Location: /error.aspx?aspxerrorpath=/busq/resultados.aspx Set-Cookie: uunico=13/09/2005:3-4043; expires=Thu, 13-Oct-2005 01:47:18 GMT; path=/ Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 164 
    Object moved to here.
    HTTP/1.1 400 Bad Request Server: Microsoft-IIS/5.0 Date: Tue, 13 Sep 2005 01:47:19 GMT Content-Type: text/html Content-Length: 87 The parameter is incorrect. 
      

  7.   

    为什么不使用CURL来进行GET或者POST,使用Socket也太不稳定了,说不定数据就没了。
      

  8.   

    用curl也不行,我将viewstates,eventTarget和eventargument都输出了,全部一样,为什么会不行呢,
    大大们可以自已试一下
    <?php
    set_time_limit(0);
    $url = "http://www.fotocasa.es/busq/resultados.aspx?idTipoInmueble=2&idTipoOferta=2&idProvincia=27&idZona1=0&idZona2=0&idBarrio=0&idOtrasZonas=0&IdPoblacion=0&idDistrito=-2&Precio=0&Superficie=0&nHabitaciones=0&idTipoVivienda=0&x=50&y=9";
    $file = file_get_contents($url);
    //取__VIEWSTATE
    if(preg_match_all("|__VIEWSTATE\'?\"?\s+value\s*=\s*\"?\"(.+?)\"|is",$file,$viewStates))
    {
    $viewState = $viewStates[1][0];
    }
    $tmp = "dgrdResultados1\$_ctl54\$_ctl2";
    $eventTarget = str_replace("$",":",$tmp);
    $eventArgument = "";//参数附加
    $file = "";
    $str = "__EVENTTARGET=$eventTarget&__EVENTARGUMENT=$eventArgument&__VIEWSTATE=$viewState";
    echo strlen($eventTarget);
    echo "<br>";
    echo "<br>";
    echo strlen($eventArgument);
    echo "<br>";
    echo "<br>";
    echo strlen($viewState);
    echo "<br>";
    echo "<br>";$ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$str);
    $file = curl_exec($ch);
    curl_close($ch);
    echo strlen($file);
    ?>