1. Apache HttpClient: CloseableHttpClient httpClient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("https://api.example.com/resource"); CloseableHttpResponse response = httpClient.execute(httpGet); try { } finally { response.close(); httpClient.close(); } 2. OkHttp: OkHttpClient client = new OkHttpClient(); RequestBody requestBody = new FormBody.Builder() .add("username", "my_username") .add("password", "my_password") .build(); Request request = new Request.Builder() .url("https://api.example.com/login") .post(requestBody) .build(); Response response = client.newCall(request).execute(); try { } finally { response.close(); } 3. Spring WebClient: WebClient webClient = WebClient.builder().build(); Mono<ClientResponse> responseMono = webClient.put() .uri("https://api.example.com/resource") .contentType(MediaType.APPLICATION_JSON) .bodyValue("{\"name\":\"John\", \"age\":30}") .exchange(); responseMono.subscribe(response -> { });


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