gpt4 book ai didi

php - 使用 file_get_contents 获取失败时的响应主体

转载 作者:搜寻专家 更新时间:2023-10-31 20:41:53 25 4
gpt4 key购买 nike

file_get_contents 的文档说

 On failure, file_get_contents() will return FALSE.

我正在与一个在响应中返回错误消息并将状态代码设置为“50x”的系统集成

有没有办法,我仍然可以获取响应内容?

最佳答案

$curl = curl_init('http://example.net');
curl_setopt( $curl, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($curl);
curl_close($curl);

但这可能无法满足您的需求,因为它需要 curl

您也可以忽略错误,仍然使用 file_get_contents

$contents = file_get_contents($url, FALSE, stream_context_create(array(
'http' => array(
'ignore_errors' => true
)
));

关于php - 使用 file_get_contents 获取失败时的响应主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20216840/

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