import org.apache.http.HttpEntity; 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 HttpGetExample { public static void main(String[] args) { try { HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet httpGet = new HttpGet("https://example.com/api"); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); String response = EntityUtils.toString(httpEntity); System.out.println(response); httpClient.getConnectionManager().shutdown(); } catch (Exception e) { e.printStackTrace(); } } }


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