如何修复';请启用cookies';使用PHP Curl时出现Cloudflare错误

如何修复';请启用cookies';使用PHP Curl时出现Cloudflare错误,php,curl,cloudflare,Php,Curl,Cloudflare,当在我的机器上本地使用postman时,我能够毫无问题地发送请求并得到回复。由于发送api的令牌无效,我应该会收到它 { "status": "Error", "message": "Invalid API Token" } 使用postman的实用程序生成php curl代码以发出此请求,我得到了以下结果 $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://

当在我的机器上本地使用postman时,我能够毫无问题地发送请求并得到回复。由于发送api的令牌无效,我应该会收到它

{
    "status": "Error",
    "message": "Invalid API Token"
}
使用postman的实用程序生成php curl代码以发出此请求,我得到了以下结果


$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://app.mobilecause.com/api/v2/reports/transactions.json",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_POSTFIELDS => "",
    CURLOPT_COOKIESESSION => true,
    CURLOPT_COOKIEFILE => "cookie.txt",
    CURLOPT_COOKIEJAR => "cookie.txt",
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => array(
        'Authorization: Token token="test_token"',
        "Content-Type: application/x-www-form-urlencoded",
        "cache-control: no-cache",
    ),
));

curl_setopt($curl, CURLOPT_VERBOSE, true);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}
在我的Web服务器上运行此代码会返回一个页面主体,该页面主体是cloudflare登录页面,具体如下所示

Please enable cookies.
One more step
Please complete the security check to access app.mobilecause.com
Why do I have to complete a CAPTCHA?
Completing the CAPTCHA proves you are a human and gives you temporary access to the web property.

What can I do to prevent this in the future?
If you are on a personal connection, like at home, you can run an anti-virus scan on your device to make sure it is not infected with malware.

If you are at an office or shared network, you can ask the network administrator to run a scan across the network looking for misconfigured or infected devices.

Cloudflare Ray ID: RAY_ID • Your IP_REDACTED • Performance & security by Cloudflare
我无法解释为什么会发生这种情况。我有一个正在写入的有效“cookie.txt”,但它似乎缺少内容

curl通过存储在“cookie.txt”中的请求写入的cookie如下所示。(编辑了潜在的敏感信息。)

邮递员通过邮递员执行命令时生成的cookie如下所示。(编辑了潜在的敏感信息。)

从本质上看,php请求似乎缺少“\uu cfruid”cookie。这可能是原因吗


将此代码复制到中会生成相同的cloudflare登录页。在我的机器上本地运行此操作会产生预期的结果。

我对kount请求也有相同的问题。。。

#HttpOnly_.app.mobilecause.com  TRUE    /   FALSE   shortStringOfNumbers    __cfduid    longStringOfNumbers
__cfruid=longStringOfNumbers-shortStringOfNumbers; path=/; domain=.app.mobilecause.com; HttpOnly; Expires=Tue, 19 Jan 2038 03:14:07 GMT;
__cfduid=longStringOfNumbers; path=/; domain=.app.mobilecause.com; HttpOnly; Expires=Thu, 23 Jan 2020 04:54:50 GMT;