php Laravel guzzle cURL 错误 6:无法解析主机:http(参见 http://curl.haxx.se/libcurl/c/libcurl-errors.html)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38909026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel guzzle cURL error 6: Could not resolve host: http (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
提问by ssuhat
On my development my code is working properly. When I push to my server it become error.
在我的开发中,我的代码工作正常。当我推送到我的服务器时,它变成了错误。
cURL error 6: Could not resolve host: http (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
cURL error 6: Could not resolve host: http (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
Here is my code:
这是我的代码:
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('/');
}
Any solution?
有什么解决办法吗?
Thanks
谢谢
回答by Tan Dat
My solution is to clear all type of caches in Artisan.
我的解决方案是清除 Artisan 中的所有类型的缓存。
Run these commands together:
一起运行这些命令:
php artisan route:clear
php artisan config:clear
php artisan cache:clear
回答by Amir No-Family
I spent a day to find that the best practice is to actually catch Exceptions in the following manner:
我花了一天的时间发现最佳实践是以以下方式实际捕获异常:
catch(\Exception $ex)
That \ makes all the difference! so DO NOT use :
这\让一切变得不同!所以不要使用:
catch(Exception $ex)
You can put this catch at the end where all other specific exceptions are caught.
您可以将此捕获放在捕获所有其他特定异常的末尾。
回答by Roderik
Your API_DOMAIN may not have been set to a proper url (did it start with http:// or https://)?
您的 API_DOMAIN 可能未设置为正确的 url(是否以 http:// 或 https:// 开头)?
It may also be worth a try to restart the web server (e.g. restart nginx).
也可能值得尝试重新启动 Web 服务器(例如重新启动 nginx)。
It could also be a connectivity issue on your server. You can try a reboot of the VPS or check if the firewall did not block your outgoing request. Maybe disable iptables or firewalld for a moment.
它也可能是您服务器上的连接问题。您可以尝试重新启动 VPS 或检查防火墙是否没有阻止您的传出请求。也许暂时禁用 iptables 或 firewalld。
There could also be issues with the DNS for the API_DOMAIN. Maybe you did configure it locally in your /etc/hosts on your developmnet environment but not on production. You may check if the dns resolves properly or add it to your /etc/hosts file on your production server.
API_DOMAIN 的 DNS 也可能存在问题。也许您确实在开发网络环境的 /etc/hosts 中本地配置了它,但没有在生产环境中配置它。您可以检查 dns 是否正确解析或将其添加到您的生产服务器上的 /etc/hosts 文件中。
回答by omarjebari
This answer helped me. It turned out to be a disparity between curl versions on OSX. Each had a version of openssl being used. Nightmare to find but a straightforward fix. See https://stackoverflow.com/a/54908305/2867894
这个答案帮助了我。事实证明,OSX 上的 curl 版本之间存在差异。每个都有一个使用的 openssl 版本。噩梦找到,但一个简单的修复。见https://stackoverflow.com/a/54908305/2867894
回答by David Enoma
I had this issue recently and it turns out that I was tunneling through a proxy server. I stopped routing through a proxy and it worked just fine.
我最近遇到了这个问题,结果证明我是通过代理服务器进行隧道传输的。我停止了通过代理进行路由,它工作得很好。
回答by Muaath Alhaddad
Just run your web server, I had the same error but my server was OFF, then I turn it on, and it works for me
只需运行您的网络服务器,我遇到了同样的错误,但我的服务器已关闭,然后我打开它,它对我有用