用已弃用的“DefaultHttpAsyncClient”替换什么?
What to replace with deprecated `DefaultHttpAsyncClient`?
我正在修改现有项目,但我发现 DefaultAsyncHttpClient
已被弃用。用什么来替换已弃用的?
HttpAsyncClient httpclient;
InputStream is = null;
try {
// TODO: deprecated ??
httpclient = new DefaultHttpAsyncClient();
httpclient.start();
try {
// some code
httpclient.shutdown();
}
catch(Exception e) {
}
}
.start()
我也无法获取该方法,我也无法获取 .shutdown
方法。
感谢帮助!
您可以使用 CloseableHttpAsyncClient 、close
代替 shutdown
CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
try {
httpclient.start();
HttpGet request = new HttpGet("http://httpbin.org/get");
Future<HttpResponse> future = httpclient.execute(request, null);
HttpResponse response = future.get();
System.out.println("Response: " + response.getStatusLine());
System.out.println("Shutting down");
} finally {
httpclient.close();
}
我正在修改现有项目,但我发现 DefaultAsyncHttpClient
已被弃用。用什么来替换已弃用的?
HttpAsyncClient httpclient;
InputStream is = null;
try {
// TODO: deprecated ??
httpclient = new DefaultHttpAsyncClient();
httpclient.start();
try {
// some code
httpclient.shutdown();
}
catch(Exception e) {
}
}
.start()
我也无法获取该方法,我也无法获取 .shutdown
方法。
感谢帮助!
您可以使用 CloseableHttpAsyncClient 、close
代替 shutdown
CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault(); try { httpclient.start(); HttpGet request = new HttpGet("http://httpbin.org/get"); Future<HttpResponse> future = httpclient.execute(request, null); HttpResponse response = future.get(); System.out.println("Response: " + response.getStatusLine()); System.out.println("Shutting down"); } finally { httpclient.close(); }