使用我的代码(如下所示),我可以随机获得的正确结果。但大多数时候我都会收到错误。
异常:
java.net.UnknownHostException: api.api.ai: Temporary failure in name resolution
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.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
注意:它确实有效。
请建议我应该从我这边检查什么设置/配置。
另请注意,我对api.api.ai的ping工作正常。
答案 0 :(得分:0)
发布解决方案以帮助其他人面临同样的问题,
关于@Hackerman所说的话:
我的wifi-extender无法处理IPV6翻译。遇到类似问题时,请务必检查wifi扩展器规格。
作为解决方案/ hack(如果你必须使用仅IPV4路由器)在启动java时使用以下
try {
assure_libusb(libusb_function_to_call(...));
}
catch(specific_libusb_exception<LIBUSB_ERROR_IO> &e)
{
:
}
catch(...)
{
throw;
}