在我的开发中,我的代码工作正常.当我推送到我的服务器时,它会变成错误.
cURL error 6: Could not resolve host: http (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
这是我的代码:
use GuzzleHttp\Client;
try {
$client = new Client();
$client->request('POST', env('API_DOMAIN') . '/v1/user/auth/verified_email',
['headers' => ['Authorization' => 'cm9vcGlhLnVzZXIud2ViOkY0RVN3VXJheS1qVVB1a18='],
'query' => ['token' => $key]]);
return redirect('/')->with('status', 'Your email has been verified. Thanks!')->with('statusType', 'success');
} catch (ConnectException $e) {
Log::error($e);
return redirect('/');
}
Run Code Online (Sandbox Code Playgroud)
有解决方案吗
谢谢
我的解决方案是清除 Artisan 中的所有类型的缓存。
一起运行这些命令:
php artisan route:clear
php artisan config:clear
php artisan cache:clear
Run Code Online (Sandbox Code Playgroud)
您的 API_DOMAIN 可能未设置为正确的 url(是否以 http:// 或 https:// 开头)?
重新启动 Web 服务器(例如重新启动 nginx)可能也值得尝试。
这也可能是您服务器上的连接问题。您可以尝试重新启动 VPS 或检查防火墙是否没有阻止您的传出请求。也许暂时禁用 iptables 或firewalld。
API_DOMAIN 的 DNS 也可能存在问题。也许您确实在开发网络环境中的 /etc/hosts 中本地配置了它,但在生产环境中却没有。您可以检查 dns 是否正确解析或将其添加到生产服务器上的 /etc/hosts 文件中。