curl - 可以ping通但不能curl
问题描述
我正在测试从本地机器连接到远程服务器。使用 ping 我可以成功连接,但如果我尝试使用 curl 它只会挂起:
使用 ping:
$ 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失败/超时:
$ 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
为什么我可以用ping
命令连接但不能用curl
命令连接?
解决方案
这可能是由于远程计算机上的端口 80 被关闭造成的。检查您的防火墙规则以确保此端口已打开。
Ping 不连接到端口(它使用 ICMP),这就是为什么 ping 在没有打开端口的情况下工作的原因。
附带说明一下,您的 ping 和 curl 命令显示您正在尝试连接到“db-machine-02”。请注意,默认情况下,数据库通常不会通过端口 80 进行通信。
推荐阅读
- matplotlib - 为什么我的 matplotlib 图只显示为 png 而不是 Matlab 数字?
- cmd - Windows 中的“sudo su”等价物
- javascript - JavaScript 抛出读取属性“提交”错误
- python - 在 Python 中编写 .format() 方法的正确方法是什么
- python - 在heroku上从rails调用python脚本进行多种操作是个好主意吗?
- node.js - 在我的 Nodejs+React+Mongo 应用程序中实现日志记录;如何确保它的可扩展性?
- c++ - Azure Devops 测试管道 LNK1107 在 MSVC 上打开 vulkan-1.lib 但在 GCC 上工作正常
- java - 当所有 JAVA 线程都是使用 OS 库创建的 Native 线程时,为什么要引入 Fork/Join 框架?
- redirect - 如何在 Grails 中正确定义重定向?
- php - 无法编辑数据库,Laravel