0

我正在修改一个现有项目,但我发现它DefaultAsyncHttpClient已被弃用。用什么替换已弃用的?

        HttpAsyncClient httpclient;
        InputStream is = null;
        try {
            // TODO: deprecated ??
            httpclient = new DefaultHttpAsyncClient();
            httpclient.start();
        try {
           
            // some code

            httpclient.shutdown();
        }
        
        catch(Exception e) {
         
        }
        }

.start()我也无法获取该方法,也无法获取.shutdown方法。

感谢您的帮助!

4

1 回答 1

0

您可以使用CloseableHttpAsyncClientclose而不是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();
   }
于 2020-06-29T08:35:52.373 回答