我需要知道客户端的 IP 地址,这是我的鳕鱼
public static void main(String[] args) throws Exception {
server = HttpServer.create(new InetSocketAddress(8000), 0);
server.createContext("/", new MyHandler());
server.setExecutor(null); // creates a default executor
server.start();
System.out.println("Client ip is: " + server.getAddress().getAddress());
}
Run Code Online (Sandbox Code Playgroud)
处理程序:
public static class MyHandler implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
t.getRemoteAddress().getAddress(); // t is 0:0:0:0:0:0:0:
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
Client ip is: /0:0:0:0:0:0:0:0
为什么我不能得到真正的客户IP?
java ×1