import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; public class HttpClientExample { public static void main(String[] args) throws Exception { HttpClient httpClient = new HttpClient(); PostMethod postMethod = new PostMethod("http://example.com/api"); postMethod.addParameter("param1", "value1"); postMethod.addParameter("param2", "value2"); int statusCode = httpClient.executeMethod(postMethod); String response = postMethod.getResponseBodyAsString(); System.out.println("Status Code: " + statusCode); System.out.println("Response: " + response); postMethod.releaseConnection(); } } httpClient.getHttpConnectionManager().getParams().setMaxTotalConnections(100); httpClient.getHttpConnectionManager().getParams().setDefaultMaxConnectionsPerHost(10); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000); httpClient.getHttpConnectionManager().getParams().setSoTimeout(5000); httpClient.getHostConfiguration().setProxy("proxy.example.com", 8080);


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