import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.methods.GetMethod; public class HttpClientExample { public static void main(String[] args) { HttpClient httpClient = new HttpClient(); HttpMethod method = new GetMethod("http://example.com"); try { int statusCode = httpClient.executeMethod(method); if (statusCode == 200) { String response = method.getResponseBodyAsString(); System.out.println("Response: " + response); } else { System.out.println("Unexpected status code: " + statusCode); } } catch (Exception e) { e.printStackTrace(); } finally { method.releaseConnection(); } } }


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