api.api.ai: 名称解析暂时失败

api.api.ai: Temporary failure in name resolution

使用我的代码(如下所示),我得到了正确的结果随机。但大多数时候我都会出错。

例外:

java.net.UnknownHostException: api.api.ai: Temporary failure in name resolution
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress.lookupAllHostAddr(InetAddress.java:928)
..<snip>...
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at PostJSON.main(PostJSON.java:34)

SSCCE 代码:

private static final String URL = "https://api.api.ai/v1/query?v=20150910";
private static final String ACCESS_CODE = "XXXXXX";
public static final HttpClient client = HttpClientBuilder.create().build();
public static final HttpPost httppost = new HttpPost(URL);

private static final String str_json = "{ query: \"how are you\", lang: \"en\", sessionId: \"somerandomthing\" }";

public static void main(String[] args) {

    try {

        HttpEntity entity = new ByteArrayEntity(str_json.getBytes("UTF-8"));
        httppost.setHeader("Content-Type",
                "application/json; charset=utf-8");
        httppost.setHeader("Authorization", "Bearer " + ACCESS_CODE);
        httppost.setEntity(entity);
        HttpResponse response = client.execute(httppost);
        String result = EntityUtils.toString(response.getEntity());
        System.out.println(result);
    } catch (Exception ex) {
        ex.printStackTrace();
    } 
}

NSLOOKUP:

zeek@zeek:$ nslookup api.ai.ai
Server:     127.0.1.1  
Address:    127.0.1.1#53

Non-authoritative answer:  
Name:   api.ai.ai  
Address: 92.242.140.21

/ETC/HOSTS

127.0.0.1   localhost
127.0.1.1   zeek

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

注意:它有时会起作用。

请建议 setting/config 我应该检查什么。

另请注意,我对 api.api.ai 的 ping 正常。

发布解决方案以帮助面临同样问题的其他人,

@Hackerman 所说的话:

我的 wifi 扩展器无法处理 IPV6 转换。遇到类似问题时,请务必检查 wifi-extender 规范。

作为 solution/hack(如果您必须使用仅支持 IPV4 的路由器)在启动时使用以下命令 java

-DpreferIPv4Stack