简体   繁体   中英

What to replace with deprecated `DefaultHttpAsyncClient`?

I'm modifying a existing project but I see that DefaultAsyncHttpClient is deprecated. What to replace the deprecated one?

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

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

.start() i cant fetch that method either and neither i can fetch .shutdown method.

Thank for help!

You can use CloseableHttpAsyncClient , close instead of 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(); }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM