小编Ben*_*min的帖子

InetAddress.getByName在代理后面失败

我正在尝试将主机名解析为其对应的IP.

我的环境是代理服务器后面的公司网络中的mac,它通过系统首选项(自动代理配置)配置.pac文件.到目前为止一切正常,我可以访问公司网络内外的资源.

解析我网络中的主机非常正常: InetAddress.getByName("host.local");

但是当我使用外部主机名时,我得到一个UnknownHostException: InetAddress.getByName("google.com");

产生

Exception in thread "main" java.net.UnknownHostException: google.com
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:850)
    at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1201)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1154)
    at java.net.InetAddress.getAllByName(InetAddress.java:1084)
    at java.net.InetAddress.getAllByName(InetAddress.java:1020)
    at java.net.InetAddress.getByName(InetAddress.java:970)
    at Test.main(Test.java:67)
Run Code Online (Sandbox Code Playgroud)

(我在Inet6AddressImpl这里有点意外)

据我所知,InetAddress.getByName使用本机机制来解析主机名.所以我认为错误不是由java jvm中缺少的代理配置引起的.

但是,如果其他一切工作正常,还能做什么呢?

一些(可能)有用的附加信息:

  • 我正在使用MacBook,ifconfig显示连接到网络的接口lo0,gif0,stf0,en0,fw0,en1 - >,带有ipv4地址.

  • nslookup google.com 在控制台上返回 ** server can't find google.com: NXDOMAIN

  • 网络中的Windows机器上的相同代码产生相同的异常

有关此错误原因的任何想法?或者还有其他方法来解析java中的主机名?

java proxy hostname resolve

5
推荐指数
1
解决办法
7011
查看次数

标签 统计

hostname ×1

java ×1

proxy ×1

resolve ×1