如果我可以使用Amazon Lex Java API与我的Bot交谈,我写了一个简单的测试程序。当我运行它时,我会得到一个 UnknownHostException:runtime.lex.eu-west-1.amazonaws.com
> Exception in thread "main" com.amazonaws.SdkClientException: Unable to execute HTTP request: runtime.lex.eu-west-1.amazonaws.com
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1114)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1064)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:743)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:717)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:513)
at com.amazonaws.services.lexruntime.AmazonLexRuntimeClient.doInvoke(AmazonLexRuntimeClient.java:531)
at com.amazonaws.services.lexruntime.AmazonLexRuntimeClient.invoke(AmazonLexRuntimeClient.java:507)
at com.amazonaws.services.lexruntime.AmazonLexRuntimeClient.executePostText(AmazonLexRuntimeClient.java:471)
at com.amazonaws.services.lexruntime.AmazonLexRuntimeClient.postText(AmazonLexRuntimeClient.java:447)
at ChatBot.ChatbotMain.main(ChatbotMain.java:17)
Caused by: java.net.UnknownHostException: runtime.lex.eu-west-1.amazonaws.com
at java.net.InetAddress.getAllByName0(InetAddress.java:1280)
at java.net.InetAddress.getAllByName(InetAddress.java:1192)
at java.net.InetAddress.getAllByName(InetAddress.java:1126)
at com.amazonaws.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:27)
at com.amazonaws.http.DelegatingDnsResolver.resolve(DelegatingDnsResolver.java:38)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:111)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.amazonaws.http.conn.ClientConnectionManagerFactory$Handler.invoke(ClientConnectionManagerFactory.java:76)
at com.amazonaws.http.conn.$Proxy8.connect(Unknown Source)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at com.amazonaws.http.apache.client.impl.SdkHttpClient.execute(SdkHttpClient.java:72)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1236)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1056)
... 11 more
现在有人如何解决这个问题? 是否有可能无法从我的公司网络发送HTTP请求?
继承守则:
package ChatBot;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.lexruntime.AmazonLexRuntime;
import com.amazonaws.services.lexruntime.AmazonLexRuntimeClientBuilder;
import com.amazonaws.services.lexruntime.model.PostTextRequest;
import com.amazonaws.services.lexruntime.model.PostTextResult;
public class ChatbotMain {
public static void main(String[]args){
AmazonLexRuntime client = AmazonLexRuntimeClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
PostTextRequest textRequest= new PostTextRequest();
textRequest.setBotName("BookTrip");
textRequest.setBotAlias("BookTripBot");
textRequest.setUserId("christester");
textRequest.setInputText("someText");
PostTextResult result = client.postText(textRequest);
System.out.println(result.getDialogState());
}
}
非常感谢,
克里斯
答案 0 :(得分:0)
问题是我公司的网络不允许与外部网络服务进行通信。我必须使用代理或网关来执行此操作