如何在Eclipse中导入"HttpClient"?我刚刚从http://hc.apache.org/downloads.cgi下载了HttpClient .我将它添加到我的Eclipse新java项目中,并希望从网站运行示例副本.
这个例子使用import org.apache.commons.httpclient.*;但是,遗憾的是,它表明Eclipse无法解决这个问题.
现在,我想知道将新发布的HttpClient导入我的项目的正确方法.是否有必要在classpath中添加一些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;
}
}
Run Code Online (Sandbox Code Playgroud)
小智 11
它有效,它解决了:
您将jar文件拖到项目中,以便在Eclipse中查看它.
要赋予Eclipse特殊的意义,请右键单击Eclipse中的jar文件,然后选择Build Path - > Add to Build Path.
现在您的导入应该正确解决.