|
发表于 2021/7/16 21:49
|
显示全部楼层
|阅读模式
|Firefox 90.0 |Mac OS X 10.15
thinkphp3.2.3
curl post 报错:Failed connect to xxx.com:443; No route to host
代码:
$this->postRequest($postUrl, http_build_query(['data'=>json_encode($params)]), [
'CURLOPT_FOLLOWLOCATION' => true,
'CURLOPT_SSL_VERIFYHOST' => false,
]);
protected function postRequest($url, $params, $opt = []) {
$curl = Curl::init();
$curl->retry(3)->set($opt)->post($params)->url($url);
if ($curl->error()) {
throw new \Exception("curl error: ".$curl->message());
} else {
$info = $curl->info();
if ($info['http_code'] != 200) {
throw new \Exception("Unexpected HTTP code: \n".print_r($info, true));
}
return $curl;
}
} |
|