问题描述
public static String asyncPost(String url,String text,Map<String,String> params) {
StringWriter writer = new StringWriter();
try (CloseableHttpAsyncclient client= getHTTPAsyncclient()) {
client.start();
HttpPost httpPost = new HttpPost(url);
httpentity postingString = new StringEntity(text,StandardCharsets.UTF_8.name());
httpPost.setEntity(postingString);
MapUtils.emptyIfNull(params).entrySet().stream().forEach(entry -> httpPost.addHeader(entry.getKey(),entry.getValue()));
final CountDownLatch latch = new CountDownLatch(1);
Future<HttpResponse> response = client.execute(httpPost,new FutureCallback<HttpResponse>() {
@Override
public void cancelled() {
// Todo Auto-generated method stub
latch.countDown();
}
@Override
public void completed(HttpResponse arg0) {
// Todo Auto-generated method stub
latch.countDown();
}
@Override
public void Failed(Exception arg0) {
// Todo Auto-generated method stub
latch.countDown();
}
});
latch.await();
IoUtils.copy(response.get().getEntity().getContent(),writer,StandardCharsets.UTF_8.toString());
} catch (IOException | KeyStoreException | NoSuchAlgorithmException | KeyManagementException | InterruptedException | UnsupportedOperationException | ExecutionException e) {
return writer.toString();
}
return writer.toString();
}
当我使用此方法从Taleo获取结果时。我得到响应,但是每次我从TALEO检索相关密钥时收到状态4(进行中)。但是,如果我发送相同的请求,则使用状态为5(完成)的POSTMAN发送。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)