<dependency> <groupId>org.kuali</groupId> <artifactId>kuali-http-client</artifactId> <version>1.0.0</version> </dependency> HttpClient httpClient = new HttpClient(); HttpMethod method = new GetMethod("http://example.com/api/resource"); int statusCode = httpClient.executeMethod(method); String response = method.getResponseBodyAsString(); if (statusCode == HttpStatus.SC_OK) { System.out.println("Success response: " + response); } else { System.out.println("Error response: " + response); } HttpMethod method = new GetMethod("http://example.com/api/resource"); method.addParameter("param1", "value1"); method.addRequestHeader("Authorization", "Bearer token"); httpClient.getParams().setConnectionTimeout(5000); httpClient.getHostConfiguration() .setProxy("proxy.example.com", 8080); Protocol https = new Protocol("https", new SSLProtocolSocketFactory(), 443); httpClient.getHostConfiguration().setHost("example.com", 443, https); Credentials credentials = new UsernamePasswordCredentials("username", "password"); httpClient.getState().setCredentials(new AuthScope("example.com", AuthScope.ANY_PORT), credentials);


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