gpt4 book ai didi

PHP file_get_contents 错误 503

转载 作者:行者123 更新时间:2023-12-02 00:37:55 31 4
gpt4 key购买 nike

我得到了错误

"503 Service Temporarily Unavailable"

我的电话

$url = "https://www.okex.com/api/v1/ticker.do?symbol=ltc_btc";
$page = json_decode(file_get_contents($url),true);
var_dump($page);

PHP file_get_contents

函数,但是当我将 url 直接写入浏览器时,我可以看到该页面,它们是否只阻止 file_get_contents 函数,或者这是如何工作的?因为如果他们阻止我的 ip,我也无法使用我的浏览器访问该站点,或者?

这是对 APi 服务器的调用,它返回我的 json。

最佳答案

更有可能是您的网页有重定向,file_get_contents() 无法处理,但浏览器可以。

所以解决方案是使用curl相反,它能够处理这些情况(例如使用 CURLOPT_FOLLOWLOCATION 选项)。

另请参阅以下问题:

这是一个可以轻松替换的片段(基于官方文档中的示例):

function curl_get_file_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);

if ($contents) return $contents;
else return FALSE;
}

关于PHP file_get_contents 错误 503,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48607332/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com