对 ip 的 REST 调用不起作用,但 localhost 有效

REST call to ip does not work, but localhost works

我在 java 中实现了一个 http 服务器(glassfish 灰熊)。

如果我向 localhost:3000/api/...提交 REST GET,我会按预期收到回复。

如果我将 REST GET 与我的 ip (192.168.0.100:3000/api...) 相加,我会得到 "no reponse error".

当我在同一网络中的另一台计算机 (192.168.0.200) 上启动 java 应用程序时,行为完全相同。对 192.168.0.100:3000/api... 的 GET 请求也会导致 "no response error".

我是不是漏了什么?

配置 GlassFish 以使用正确的 HTTP 侦听器。

https://docs.oracle.com/cd/E19776-01/820-4495/ggnfu/index.html

For example, an HTTP listener can listen on all configured IP addresses on a given port for a host by specifying the IP address 0.0.0.0. Alternatively, the HTTP listener can specify a unique IP address for each listener while using the same port.

在地址 0.0.0.0 上定义一个侦听器以侦听主机的所有地址,或者更具体地告诉它仅在地址 192.168.0.100 上侦听。