gpt4 book ai didi

php curl_exec 返回空

转载 作者:可可西里 更新时间:2023-10-31 22:19:23 26 4
gpt4 key购买 nike

 $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy); // $proxy is ip of proxy server
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$httpCode = curl_getinfo($ch , CURLINFO_HTTP_CODE); // this results 0 every time
echo '<br> curl'.$ch; //this line outputs resource id#5
$exec = stripslashes(curl_exec($ch));
echo '<br> exec'.curl_exec($ch); //this results blank

我很困惑为什么 $exec 不返回任何东西,我是 curl 的新手请帮忙,在此先感谢

最佳答案

curl_exec当请求失败时将返回 false。为此调整您的功能:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy); // $proxy is ip of proxy server
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

$httpCode = curl_getinfo($ch , CURLINFO_HTTP_CODE); // this results 0 every time
$response = curl_exec($ch);

if ($response === false)
$response = curl_error($ch);

echo stripslashes($response);

curl_close($ch);

这样你会看到 curl 错误

关于php curl_exec 返回空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27121324/

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