curl错误HTTP状态代码0——来自服务器的空回复


curl error HTTP status code 0-- empty reply from server

我正试图废弃一个网站,但它总是说Empty Reply from server有人能看看code,告诉我我做错了什么吗?

这是code

function spider($url){
        $header = array(
            "Host" => "www.example.net",
            //"Accept-Encoding:gzip,deflate,sdch",
            "Accept-Language:en-US,en;q=0.8",
            "Cache-Control:max-age=0",
            "Connection:keep-alive","Content-Length:725","Content-Type:application/x-www-form-urlencoded",
            'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
            ,"X-Requested-With:XMLHttpRequest"
        );
        $cookie = "cookie.txt";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return page 1:yes
        curl_setopt($ch, CURLOPT_TIMEOUT, 200); // http request time-out 20 seconds
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the URL changes
        curl_setopt($ch, CURLOPT_MAXREDIRS, 2); //if http server gives redirection response
        curl_setopt($ch, CURLOPT_USERAGENT,
        "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7");
        curl_setopt($ch, CURLOPT_COOKIEJAR, realpath( $cookie)); // cookies storage / here the changes have been made
        curl_setopt($ch, CURLOPT_COOKIEFILE, realpath( $cookie));
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS,"view=ViewDistrict&param=7&uniqueid=1397991494188&PHPSESSID=f134vrnv7glosgojvf4n1mp7o2&page=http%3A%2F%2Fwww.example.com%2Fxhr.php");
        curl_setopt($ch, CURLOPT_REFERER, $url);
        curl_setopt($ch, CURLOPT_REFERER, "http://www.example.com/");
        $data = curl_exec($ch); // execute the http request
        $info = curl_getinfo($ch);
        curl_close($ch); // close the connection
        return $data;
}

这是function call

echo spider("http://www.example.net/");

编辑

Array ( [url] => http://www.example.net/ [content_type] => text/html [http_code] => 301 [header_size] => 196 [request_size] => 840 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 1 [total_time] => 61.359 [namelookup_time] => 0 [connect_time] => 0.281 [pretransfer_time] => 0.281 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 178 [upload_content_length] => 0 [starttransfer_time] => 60.593 [redirect_time] => 0.766 [certinfo] => Array ( ) [redirect_url] => ) Empty reply from server

这是标题我也更新了我的post data现在curl_setopt($ch, CURLOPT_POSTFIELDS,"view=ViewDistrict&param=7&uniqueid=".time(). rand(101,500)."&PHPSESSID=f134vrnv7glosgojvf4n1mp7o2&page=http%3A%2F%2Fexample.com%2Fxhr.php");

并且还从CCD_ 8 中去除了CCD_

您尝试过将其从标头中删除吗?

X-Requested-With:XMLHttpRequest

我猜你的问题在这一行:

curl_setopt(
    $ch,
    CURLOPT_POSTFIELDS,
    "view=ViewDistrict&param=7&uniqueid=1397991494188&PHPSESSID=f134vrnv7glosgojvf4n1mp7o2&page=http%3A%2F%2Fwww.example.com%2Fxhr.php"
);

请注意,您正在传递PHPSESSID的值。我猜你抄袭了&粘贴了一个访问该网站的URL,对吧?当你访问该网站时,该会话ID可能是有效的,但现在有效的可能性很小。如果服务器不喜欢会话ID,很可能它不会给你任何数据。