CUrl,Pecl HTTPRequest,file_get_contents()没有工作

时间:2015-07-09 14:15:58

标签: stack httprequest file-get-contents forever

也许我只有另一个糟糕的一天,但我已经尝试了所有可能的方式来发送带有Cookie的GET请求,并且每一个都被堆叠。我的页面正在重新加载。

我的$ url =" http://localhost/content-search/demo/"

首次尝试从Pecl使用类HTTPRequest ...我删除了它,

但是我试图用curl发送它:

public static function sendRequest($url, array $cookies) {
    $c = curl_init($url);
    curl_setopt($c, CURLOPT_VERBOSE, 1);
    curl_setopt($c, CURLOPT_COOKIE, $cookies);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    $page = curl_exec($c);
    curl_close($c);
    return $page;
}

使用file_get_contents:

public static function sendRequest($url, $cookies)
{
    if(is_array($cookies)) {
        $cookies = self::formatCookies($cookies);
    }

    $options = array(
        'http' => array(
            'method' => 'GET',
            'header' => 'Connection: close\r\nCookie: ' . $cookies
        )
    );
    return file_get_contents($url, NULL, stream_context_create($options));
}

再次,他们三个都堆叠起来,请求就像永远一样被发送。

1 个答案:

答案 0 :(得分:0)

好的解决了!

问题出现在cookies中。 session_write_close(); 解决问题:)

相关问题