无法连接到 www.googleapis.com 端口 443:网络无法访问 [英] Failed to connect to www.googleapis.com port 443: Network unreachable

查看:632
本文介绍了无法连接到 www.googleapis.com 端口 443:网络无法访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Google 客户端 API.我按照此处的说明进行操作,但是当我调用 $client->认证($代码);命令抛出异常,说明:
无法连接到 www.googleapis.com 端口 443:网络无法访问
有什么问题?

I'm trying to implement google sign-in in my website that is written in Symfony2 using Google Client API. I followed the instructions here, but when I call $client->authenticate($code); command an exception is thrown telling that:
Failed to connect to www.googleapis.com port 443: Network unreachable
What is the problem?

推荐答案

解决方案 2(来自更新).这似乎是 ipv6 接口和 php curl 的一些错误,所以另一种解决方案是在 curl 函数中设置适当的选项,以在您的 php 脚本中使用 ipv4 连接到远程服务器

Solution 2 (from update). it seems to be some bug with ipv6 interfaces and curl with php, so another solution is to set the appropiate option in curl function to connect to the remote server with ipv4 in your php script

curl_setopt( $curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

curl_setopt( $curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

解决方案 1.

同样的事情发生在我身上(通过将 ip v4 和主机名添加到/etc/hosts 文件来解决),正如@hans-z 在另一个答案评论中所指出的,我尝试使用 next 命令来验证网络问题.

The same happened to me (solved by adding the ip v4 and hostname to /etc/hosts file), As pointed by @hans-z in another answer comment, I tried using next command to validate the network issue.

curl -v https://www.googleapis.com 

结果是随机的,只有十分之一的尝试 curl 命令可以连接到服务器,响应类似于:(La red es inaccesible"在英语中的意思是网络无法访问":)

It turned out that it was randomly, and only 1 in 10 tries the curl command could connect to the server, the response was something like: ("La red es inaccesible" means in english "network unreachable" :) )

$ curl -v https://www.googleapis.com
* Rebuilt URL to: https://www.googleapis.com/
* Hostname was NOT found in DNS cache
*   Trying 64.233.186.95...
*   Trying 2800:3f0:4003:c00::5f...
* connect to 2800:3f0:4003:c00::5f port 443 failed: La red es inaccesible
* Failed to connect to www.googleapis.com port 443: La red es inaccesible
* Closing connection 0
curl: (7) Failed to connect to www.googleapis.com port 443: La red es inaccesible

成功的响应是:

curl -v https://www.googleapis.com
* Rebuilt URL to: https://www.googleapis.com/
* Hostname was NOT found in DNS cache
*   Trying 64.233.186.95...
*   Trying 2800:3f0:4003:c00::5f...
* Connected to www.googleapis.com (64.233.186.95) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using ECDHE-RSA-AES128-GCM-SHA256
* Server certificate:
*    subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.storage.googleapis.com
*    start date: 2015-04-08 14:12:01 GMT
*    expire date: 2015-07-07 00:00:00 GMT
*    subjectAltName: www.googleapis.com matched
*    issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
*    SSL certificate verify ok.
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: www.googleapis.com
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: Fri, 01 Jan 1990 00:00:00 GMT
< Date: Tue, 21 Apr 2015 21:38:12 GMT
< Vary: X-Origin
< Content-Type: text/html; charset=UTF-8
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
* Server GSE is not blacklisted
< Server: GSE
< Alternate-Protocol: 443:quic,p=1
< Accept-Ranges: none
< Vary: Origin,Accept-Encoding
< Transfer-Encoding: chunked
< 
* Connection #0 to host www.googleapis.com left intact

奇怪的消息是在 DNS 缓存中找不到主机名",我使用的是 google DNS 的 4.4.4.4 和 8.8.8.8,所以我使用 curl 命令输出中的 ipv4 将该域添加到我的/etc/hosts 文件中问题就解决了.

The weird message was "Hostname was NOT found in DNS cache", I was using google DNS's 4.4.4.4 and 8.8.8.8, so I added that domain to my /etc/hosts file using the ipv4 from the curl command output and the problem was solved.

#/etc/hosts
...
64.233.186.95 www.googleapis.com
#DONT COPY THIS IP, USE THE ONE FROM YOUR CURL OUTPUT
...

这篇关于无法连接到 www.googleapis.com 端口 443:网络无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆