import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; public class HttpClientExample { private static final String URL = "https://www.example.com/api"; public static void main(String[] args) { HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet httpGet = new HttpGet(URL); try { HttpResponse response = httpClient.execute(httpGet); String responseBody = EntityUtils.toString(response.getEntity()); System.out.println("Response Code : " + response.getStatusLine().getStatusCode()); System.out.println("Response Body : " + responseBody); } catch (Exception e) { e.printStackTrace(); } } }


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