【发布时间】:2010-08-05 21:28:51
【问题描述】:
谁有关于如何编写 java 或 javafx cURL 应用程序的好教程?我已经看过很多关于如何启动外部调用来表示 XML 文件的教程,但是我试图检索的 XML 提要调用要求您在能够检索 XML 提要之前提交用户名和密码。
【问题讨论】:
谁有关于如何编写 java 或 javafx cURL 应用程序的好教程?我已经看过很多关于如何启动外部调用来表示 XML 文件的教程,但是我试图检索的 XML 提要调用要求您在能够检索 XML 提要之前提交用户名和密码。
【问题讨论】:
你想完成什么?您是否尝试通过 HTTP 检索 XML 提要?
在这种情况下,我建议您查看Apache HttpClient。它以纯 Java 方式提供与 cURL 类似的功能(cURL 是本机 C 应用程序)。 HttpClient 支持多个authentication mechanisms。例如,您可以像这样使用基本身份验证提交用户名/密码:
public static void main(String[] args) throws Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope("localhost", 443),
new UsernamePasswordCredentials("username", "password"));
HttpGet httpget = new HttpGet("https://localhost/protected");
System.out.println("executing request" + httpget.getRequestLine());
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
}
if (entity != null) {
entity.consumeContent();
}
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
查看more examples 的网站。
【讨论】: