import org.apache.http.*; import org.apache.http.client.*; import org.apache.http.impl.client.*; import org.apache.http.client.methods.*; public class HttpClientExample { public static void main(String[] args) { CloseableHttpClient httpClient = HttpClients.createDefault(); try { HttpGet getRequest = new HttpGet("http://example.com"); CloseableHttpResponse response = httpClient.execute(getRequest); HttpEntity responseEntity = response.getEntity(); System.out.println("Response Status Code: " + response.getStatusLine().getStatusCode()); System.out.println("Response Body: " + EntityUtils.toString(responseEntity)); response.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { httpClient.close(); } catch (Exception e) { e.printStackTrace(); } } } }


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