import com.github.async.http.client.AsyncHttpClient; import com.github.async.http.client.AsyncHttpClientConfig; import org.asynchttpclient.ListenableFuture; import org.asynchttpclient.Response; public class YAAHCSample { public static void main(String[] args) { AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder() .setConnectTimeout(5000) .setRequestTimeout(10000) .build(); AsyncHttpClient asyncHttpClient = new AsyncHttpClient(config); String url = "https://api.example.com/endPoint"; ListenableFuture<Response> future = asyncHttpClient.prepareGet(url).execute(); future.addListener(() -> { try { Response response = future.get(); System.out.println("Response: " + response.getResponseBody()); } catch (Exception e) { e.printStackTrace(); } finally { asyncHttpClient.close(); } }, asyncHttpClient); } }


上一篇:
下一篇:
切换中文