PHP文件获取内容& cURL没有显示任何内容

时间:2017-12-17 22:56:11

标签: php api curl

我检查过,看起来在php.ini文件中启用了cURL(我使用XAMPP),但它仍然没有显示任何内容。 file_get_contents也是如此。我只是得到一个空白的网页...

<body>
<?php
$auth = base64_encode("04d2ac7f76a0fbc0eee9dc5ef96b9259:dc70ffc7ad911236bc2e0822855e2d42");
$context = stream_context_create(['http' => ['header' => "Authorization: Basic $auth"]]);
$homepage = file_get_contents("https://api.intrinio.com/companies?identifier=AA", false, $context );


$login = '04d2ac7f76a0fbc0eee9dc5ef96b9259';
$password = 'dc70ffc7ad911236bc2e0822855e2d42';
$url = 'https://api.intrinio.com/companies?identifier=AA';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
$result = curl_exec($ch);
curl_close($ch);  
echo($result);
?>
</body>

任何人都知道为什么? 谢谢!

1 个答案:

答案 0 :(得分:0)

解决方案:

$auth = base64_encode("04d2ac7f76a0fbc0eee9dc5ef96b9259:dc70ffc7ad911236bc2e0822855e2d42"); 
$context = stream_context_create(['http' => ['header' => "Authorization: Basic $auth"]]); 
$homepage = file_get_contents("https://api.intrinio.com/companies?identifier=AA", false, $context ); 
$jsonary = json_decode($homepage,TRUE); 
print_r($jsonary); 

那就是说,卷曲仍然不起作用,所以如果有人知道如何解决它,那么如果你能告诉我,我仍然会感激。

相关问题