用于HTTP POST,GET等的最佳Java库是什么?[已关闭]
在性能,稳定性,成熟度等方面,用于HTTP POST,GET等的最佳Java库是什么?有没有一个特定的库比其他库使用得更多?
我的要求是将 HTTPS POST 请求提交到远程服务器。我过去使用过 java.net.*软件包以及org.apache.commons.httpclient.*软件包。两者都完成了工作,但我希望您的一些意见/建议。
在性能,稳定性,成熟度等方面,用于HTTP POST,GET等的最佳Java库是什么?有没有一个特定的库比其他库使用得更多?
我的要求是将 HTTPS POST 请求提交到远程服务器。我过去使用过 java.net.*软件包以及org.apache.commons.httpclient.*软件包。两者都完成了工作,但我希望您的一些意见/建议。
imho: Apache HTTP Client
用法示例:
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
import java.io.*;
public class HttpClientTutorial {
private static String url = "http://www.apache.org/";
public static void main(String[] args) {
// Create an instance of HttpClient.
HttpClient client = new HttpClient();
// Create a method instance.
GetMethod method = new GetMethod(url);
// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
try {
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
// Read the response body.
byte[] responseBody = method.getResponseBody();
// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
System.out.println(new String(responseBody));
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}
}
}
一些突出的功能:
我会推荐Apache HttpComponents HttpClient,Commons HttpClient的继承者
我还建议看看HtmlUnit。HtmlUnit是一个“用于Java程序的无GUI浏览器”。http://htmlunit.sourceforge.net/