$endpoint = rtrim($site->url,"/").'/'.env('WP_ENDPOINT');
try {
$request = Http::post($endpoint);
dd($request);
} catch (\Guzzle\Http\Exception\ConnectException $e) {
$response = json_encode((string)$e->getResponse()->getBody());
}
我尝试使用 guzzle http 客户端从远程 URL 获取响应,但在第 4 行收到错误“cURL 错误 6:无法解析主机:”。
$request = Http::post($endpoint);
我使用了 try catch 来处理错误,但到目前为止什么也没发生。
任何帮助将不胜感激。
实际上,我没有在任何时候使用 laravel guzzle,但我读过一些有关 guzzle 请求的内容,你应该始终捕获这两种类型的常见超时,连接超时和请求超时,你可以像这样尝试你的发布请求吗:
$retry_count = 0;
do{
try{
$response = $client->post($endpoint);
}
catch (\GuzzleHttp\Exception\ConnectException $e) {
// log the error here
Log::Warning('guzzle_connect_exception', [
'url' => $this->request->fullUrl(),
'message' => $e->getMessage()
]);
}
catch (\GuzzleHttp\Exception\RequestException $e) {
Log::Warning('guzzle_connection_timeout', [
'url' => $this->request->fullUrl(),
'message' => $e->getMessage()
]);
}
if(++retry_count == 5){
break;
}
}while(!is_array($response));
如果您发现此代码有任何问题,请通知我!