現在、私はプロジェクトに取り組んでいます。私のモジュールはHttpClientを使って外部APIの1つを呼び出す必要があります。Java:HttpPost to API - ConnectTimeoutException - Apache HttpClient 4
私はPOSTMANを使用してAPIに手動でアクセスしましたが、正常に接続して結果を得ることができますが、コードを実行するとorg.apache.http.conn.ConnectTimeoutExceptionが発生しました。
外部API:遭遇
http://10.9.11.222:8500/api/getDocs
PostToApi class:
HttpPost httpPost = new HttpPost("http://10.9.11.222:8500/api/getDocs");
StringEntity stringEntity = new StringEntity(jsonToBeSent);
httpPost.addHeader("Content-type", "application/json");
httpPost.setEntity(stringEntity);
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity, "UTF-8");
serverResponse[0]=String.valueOf(response.getStatusLine().getStatusCode());
serverResponse[1]=responseString;
が例外:
org.apache.http.conn.ConnectTimeoutException: Connect to 10.9.11.222:8500 [/ 10.9.11.222] failed: connect timed out
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:143)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
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.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:117)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at element.bst.elementexploration.rest.util.PostToServer.post(PostToServer.java:58)
ありがとうございます、私はそのAPIをチェックします:) – iamj