Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
可以连接ping,但不能连接curl_Curl_Ping - Fatal编程技术网

可以连接ping,但不能连接curl

可以连接ping,但不能连接curl,curl,ping,Curl,Ping,我正在测试从本地计算机连接到远程服务器。使用ping,我可以成功连接,但如果我尝试使用curl,它将挂起: 使用ping: 使用curl失败/超时: 为什么我可以用ping命令连接,而不能用curl命令连接?这可能是由于远程计算机上的端口80关闭造成的。 检查防火墙规则以确保此端口已打开 Ping没有连接到它使用ICMP的端口,因此Ping在没有打开端口的情况下工作 另一方面,ping和curl命令显示您正在尝试连接到db-machine-02。请注意,默认情况下,数据库通常不会通过端口80进行

我正在测试从本地计算机连接到远程服务器。使用ping,我可以成功连接,但如果我尝试使用curl,它将挂起:

使用ping:

使用curl失败/超时:


为什么我可以用ping命令连接,而不能用curl命令连接?

这可能是由于远程计算机上的端口80关闭造成的。 检查防火墙规则以确保此端口已打开

Ping没有连接到它使用ICMP的端口,因此Ping在没有打开端口的情况下工作


另一方面,ping和curl命令显示您正在尝试连接到db-machine-02。请注意,默认情况下,数据库通常不会通过端口80进行通信。

如果使用代理服务器,则如果代理服务器无法“看到”目标主机,您可能会遇到问题。例如,如果使用测试或开发环境,并且linux开发主机配置为使用公司代理,则可能需要配置或覆盖no_proxy环境变量

例如:覆盖no_代理使curl能够在从本地VM dev box访问本地VM web服务器时工作,并且http_代理被设置为公司代理。在linux中,一个选项是在发出curl命令时覆盖no_代理:


好的,所以在没有指定端口的情况下用curl测试连接是不可能的?没错。如果未指定端口或协议,默认情况下,curl将尝试建立到端口80的HTTP连接。正如您在curl命令的输出中所看到的那样。
$ ping db-machine-02
Pinging db-machine-02.comp.org [xxx.xx.x.xxx] with 32 bytes of data:
Reply from xxx.xx.x.xxx: bytes=32 time=12ms TTL=51
Reply from xxx.xx.x.xxx: bytes=32 time=12ms TTL=51
Reply from xxx.xx.x.xxx: bytes=32 time=12ms TTL=51
Reply from xxx.xx.x.xxx: bytes=32 time=12ms TTL=51

Ping statistics for xxx.xx.x.xxx:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 12ms, Maximum = 12ms, Average = 12ms
$ curl -v db-machine-02
* STATE: INIT => CONNECT handle 0x600077108; line 1332 (connection #-5000)
* Added connection 0. The cache now contains 1 members
* STATE: CONNECT => WAITRESOLVE handle 0x600077108; line 1373 (connection #0)
*   Trying xxx.xx.x.xxx:80...
* TCP_NODELAY set
* STATE: WAITRESOLVE => WAITCONNECT handle 0x600077108; line 1452 (connection #0)
* Connection timed out after 300181 milliseconds
* multi_done
* Closing connection 0
* The cache now contains 0 members
curl: (28) Connection timed out after 300181 milliseconds
joe@vm-dev-host:~$ no_proxy="192.168.1.123" curl -X GET "http://192.168.1.123/somedata"