CURL 未提供任何值


CURL is not providing any values

我下面的PHP代码不起作用。我已经创建了在代码中共享的测试用户ID和密码。文件没有任何值。但是我看到每次执行此代码时都会对其进行编辑。

<?php
$username = '8632465';
$password = 'basade41';
$loginUrl = 'https://cabinet.instaforex.com/partner/login';
//$userAgent = 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0';
$config['useragent'] = 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0';
//$userAgent = $_SERVER['HTTP_USER_AGENT'];
//init curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $config['useragent']);
//Set the URL to work with
curl_setopt($ch, CURLOPT_URL, $loginUrl);
// ENABLE HTTP POST
curl_setopt($ch, CURLOPT_POST, 1);
//Set the post parameters
curl_setopt($ch, CURLOPT_POSTFIELDS, 'user='.$username.'&pass='.$password);
//Handle cookies for the login
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
//Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
//not to print out the results of its query.
//Instead, it will return the results as a string return value
//from curl_exec() instead of the usual true/false.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//execute the request (the login)
$store = curl_exec($ch);
//the login is now done and you can continue to get the
//protected content.
//set the URL to the protected file
curl_setopt($ch, CURLOPT_URL, 'https://cabinet.instaforex.com/partner/aff_statistic');
//execute the request
$content = curl_exec($ch);
//save the data to disk
file_put_contents('c:/xampp/htdocs/upload/test.txt', $content);
?>

我认为您的代码缺少一些设置。 例如:CURLOPT_CAINFO...这是我的https代码

<?php
//The CA certificate path
$caDir = '....../GeoTrustGlobalCA.crt';
//cookie file path
$cookieDir = '......';
//URL
$url = 'https://www.zhihu.com/......';
$defaultOpt = array(
    CURLOPT_RETURNTRANSFER => true,     // return web page
    CURLOPT_HEADER         => false,    // don't return headers
    CURLOPT_FOLLOWLOCATION => true,     // follow redirects
    CURLOPT_ENCODING       => "",       // handle all encodings
    CURLOPT_USERAGENT      => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36",
    CURLOPT_AUTOREFERER    => true,     // set referer on redirect
    CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
    CURLOPT_TIMEOUT        => 120,      // timeout on response
    CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
    CURLOPT_SSL_VERIFYPEER => true,     // enabled SSL Cert checks
    CURLOPT_SSL_VERIFYHOST => 2,
    CURLOPT_CAINFO         => $caDir,
    CURLOPT_COOKIEFILE     => $cookieDir,
    CURLOPT_COOKIEJAR      => $cookieDir,
    CURLOPT_URL            => $url,
    CURLOPT_HTTPGET        => true      //method is GET
);
$handle = curl_init();
curl_setopt_array($handle,$arrOpt);
$content = curl_exec($handle);
$err     = curl_errno($handle);
$errmsg  = curl_error($handle);
$header  = curl_getinfo($handle);
curl_close($handle);
printf("Content is %s", $content);
?>
你可以参考这篇文章php-curl-https(

在(^__^))或这个使用-curl-in-php-to-access-https-ssltls-protected-sites。