Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP cURL | cURL不使用GET请求发送cookie_Php_Curl_Cookies - Fatal编程技术网

PHP cURL | cURL不使用GET请求发送cookie

PHP cURL | cURL不使用GET请求发送cookie,php,curl,cookies,Php,Curl,Cookies,我正在尝试发送带有GET请求的cookies。它只适用于POST请求。这是我的POST请求功能,它可以工作: function post() { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://xxxxxxxx.xx/dashboard/GetAdvertisersTable'); $body = "force=true&query.id=&query.advertiser=";

我正在尝试发送带有GET请求的cookies。它只适用于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: */*

尝试更改
dirname(_文件)。“cookies.txt”
dirname(_文件)。“/cookies.txt”
-cookies之前没有斜杠。使用https,您应该包括
curl\u setopt($ch,CURLOPT\u SSL\u VERIFYHOST,false);curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false)-但我不确定这是否会影响cookies处理