PHP cURL | CURL不发送带有GET请求的cookie

时间:2015-03-04 12:05:10

标签: php curl cookies

我正在尝试使用GET请求发送Cookie。它仅适用于POST请求。这是我的POST请求函数:

function post()
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://xxxxxxxx.xx/dashboard/GetAdvertisersTable');
    $body = "force=true&query.id=&query.advertiser=";
    curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

    //Handle cookies for the login
    curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
    curl_setopt( $ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "cookies.txt" );
    curl_setopt( $ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "cookies.txt" );

    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    var_dump(curl_exec($ch));
    var_dump(curl_getinfo($ch));
    curl_close($ch);
}

这是GET请求函数:

function get()
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://xxxxxxx.com/Reports/GetCampaignInsights?id=fqlwi7u3');
    //Handle cookies for the login
    curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
    curl_setopt( $ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "cookies.txt" );
    curl_setopt( $ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "cookies.txt" );
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    var_dump(curl_exec($ch));
    var_dump(curl_getinfo($ch));
    curl_close($ch);
}

调试标题后,我在标题

中找不到cookie字段
GET /Reports/GetCampaignInsights?id=fqlwi7u3 HTTP/1.1
Host: xxxxxxxx.com
Accept: */*

0 个答案:

没有答案