无法连接到www.googleapis.com端口443:网络无法访问

时间:2015-02-06 13:00:40

标签: php symfony google-login google-client

我试图在我的网站中使用Google Client API在Symfony2中编写谷歌登录。我按照here的说明进行操作,但是当我调用$ client-> authenticate($ code)时;命令抛出异常,告知:
无法连接到www.googleapis.com端口443:网络无法访问
有什么问题?

5 个答案:

答案 0 :(得分:7)

解决方案2(来自更新)。 它似乎是ipv6接口和curl与php的一些错误,所以另一个解决方案是在curl函数中设置appropiate选项,用你的PHP脚本中的ipv4连接到远程服务器

curl_setopt($ curl,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);


解决方案1。

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

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

原来它是随机的,只有十分之一的尝试curl命令可以连接到服务器,响应类似于: (“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...
* 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缓存中找不到主机名”,我使用的是谷歌DNS 4.4.4.4和8.8.8.8,所以我使用curl命令输出中的ipv4将该域添加到我的/ etc / hosts文件中问题解决了。

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

答案 1 :(得分:3)

看起来像是一个传出的防火墙/代理/网络问题。您应该可以从运行网站的计算机上验证是否使用pingcurl

答案 2 :(得分:3)

如果你的网络在代理下。您应该设置代理URL和端口

curl_setopt($ch, CURLOPT_PROXY, "http://url.com"); //your proxy url
curl_setopt($ch, CURLOPT_PROXYPORT, "80"); // your proxy port number

这解决了我的问题

答案 3 :(得分:1)

试试这个echo ipv4&gt;&gt; 〜/ .curlrc。 它为我工作。

答案 4 :(得分:0)

有同样的问题 - 问题在于dns解析,就像le0diaz的答案中提到的那样。

在ubuntu 16.04上,我们可以通过chaning /etc/gai.conf来解决它,更改IPv6的presedance,取消注释以下行: precedence :: ffff:0:0/96 100