【问题标题】:PHP - File_get_contents doesn't detect CURL responcePHP - File_get_contents 未检测到 CURL 响应
【发布时间】:2018-11-02 19:08:10
【问题描述】:

我的脚本在这里:

<?php

$auth_token = "privateprivateprivate";
$curl = curl_init("https://api-sandbox.coingate.com/v2/orders/");

$headers = array();
$headers[] = "Authorization: Token " .$auth_token;




$output = curl_exec($curl);
$output_json = file_get_contents($output);
$output_array = json_decode($output_json);

$message = $output_array["message"];
$reason  = $output_array["reason"];

echo $message;
echo $reason;
?>

我要做的是调用“https://api-sandbox.coingate.com/v2/orders/”并使用 PHP 的file_get_contents() 函数获取信息。

该文件的结果是 JSON,因此我进行了基本解码,但是当我运行 php 脚本时,它显示: file_get_contents(): 文件名在...中不能为空

这是我第一次尝试使用 curl,我可以得到一些帮助吗?

谢谢!

【问题讨论】:

标签: php json curl file-get-contents


【解决方案1】:

要返回请求的数据并将其保存到变量中,您可以使用带有CURLOPT_RETURNTRANSFER 选项的curl_setopt 函数:

<?php

$auth_token = "privateprivateprivate";
$headers = [
    "Authorization: Token " .$auth_token,
];

$curl = curl_init("https://api-sandbox.coingate.com/v2/orders/");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

$output = curl_exec($curl);
$output_array = json_decode($output);

var_dump($output, $output_array);

要了解更多信息,您可以查看 PHP cURL 文档:http://de.php.net/manual/de/book.curl.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-15
    • 2021-12-31
    • 1970-01-01
    • 2012-06-19
    • 2011-06-23
    • 1970-01-01
    • 2013-07-23
    • 2015-07-23
    相关资源
    最近更新 更多