2026世界杯在哪_世界杯亚洲预选赛积分 - ifexchina.com

java - 如何将“HttpClient”导入 Eclipse?

如何在 Eclipse 中导入“HttpClient”?我刚才从http://hc.apache.org/downloads.cgi下载了HttpClient 。我将它添加到我的 Eclipse 新 java 项目中,并希望从网站运行示例副本。

这个例子使用import org.apache.commons.httpclient.*;了 但是,可惜的是,它表明 Eclipse 无法解决这个问题。

现在,我想知道将新发布的 HttpClient 导入我的项目的正确方法。是否有必要在类路径中添加一些 jar?它是什么?

这是我运行的整个示例。我猜新发布的“HTTPClient”改变了它的导入jar,是真的吗?

package http.demo;

import java.io.IOException;

import org.apache.commons.httpclient.*;

import org.apache.commons.httpclient.methods.*;

public class SimpleHttpClient {

public static void main(String[] args) throws IOException {

HttpClient client = new HttpClient();

client.getHostConfiguration().setHost( "www.imobile.com.cn" , 80, "http" );

method = getPostMethod();

client.executeMethod(method);

System.out.println(method.getStatusLine());

Stringresponse=newString(method.getResponseBodyAsString().getBytes("8859_1"));

System.out.println(response);

method.releaseConnection();

}

private static HttpMethod getGetMethod(){

return new GetMethod("/simcard.php?simcard=1330227");

}

private static HttpMethod getPostMethod(){

PostMethod post = new PostMethod( "/simcard.php" );

NameValuePair simcard = new NameValuePair( "simcard" , "1330227" );

post.setRequestBody( new NameValuePair[] { simcard});

return post;

}

}