阿帕奇HttpClient的不存在。错误 [英] Apache httpclient does not exist. Error
问题描述
您好我不断收到错误
Hi I keep getting an errors
test.java:15: package org.apache.commons.httpclient does not exist
import org.apache.commons.httpclient.Cookie;
^
test.java:16: package org.apache.commons.httpclient does not exist
import org.apache.commons.httpclient.HttpState;
^
test.java:17: package org.apache.commons.httpclient does not exist
import org.apache.commons.httpclient.HttpClient;
^
test.java:18: package org.apache.commons.httpclient.methods does not exist
import org.apache.commons.httpclient.methods.GetMethod;
^
test.java:22: cannot find symbol
symbol : class HttpClient
location: class test
HttpClient client = new HttpClient();
^
test.java:22: cannot find symbol
symbol : class HttpClient
location: class test
HttpClient client = new HttpClient();
^
test.java:26: cannot find symbol
symbol : class GetMethod
location: class test
GetMethod method = new GetMethod("https://online.investools.com/authentication/auth.iedu");
^
test.java:26: cannot find symbol
symbol : class GetMethod
location: class test
GetMethod method = new GetMethod("https://online.investools.com/authentication/auth.iedu");
^
test.java:29: cannot find symbol
symbol : class Cookie
location: class test
Cookie[] cookies = client.getState().getCookies();
^
test.java:31: cannot find symbol
symbol : class Cookie
location: class test
Cookie cookie = cookies[i];
^
10 errors
编译我用
javac -cp ;./httpclient-4.2.jar;jsoup-1.6.3.jar test.java
这就是code
and this is the code
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
public class test{
public static void main (String []args)throws IOException{
HttpClient client = new HttpClient();
client.getParams().setParameter("username", "SomeUSER");
client.getParams().setParameter("password", "GF@QT#$WE");
GetMethod method = new GetMethod("https://online.investools.com/authentication/auth.iedu");
try{
client.executeMethod(method);
Cookie[] cookies = client.getState().getCookies();
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
System.err.println(
"Cookie: " + cookie.getName() +
", Value: " + cookie.getValue() +
", IsPersistent?: " + cookie.isPersistent() +
", Expiry Date: " + cookie.getExpiryDate() +
", Comment: " + cookie.getComment());
}
client.executeMethod(method);
}
catch(Exception e) {
System.err.println(e);
}
finally {
method.releaseConnection();
}
我很迷茫,不知道我在做什么错。我认为这很简单,但我已经检查好几次,它的存在和jsoup编译罚款。
谢谢
I am very confused and don't know what I'm doing wrong. I think it is simple, but I have checked several times and it exists and jsoup compiles fine. Thanks
推荐答案
我相信你想 org.apache.http.client
如果你使用的HttpClient 4.2 (它看起来像你)。在 org.apache.commons.httpclient
包是为旧版本。
I believe you want org.apache.http.client
if you're using HttpClient 4.2 (which it looks like you are). The org.apache.commons.httpclient
package is for the older version.
编辑:没有的所有的这是在的HttpClient
现在在班 http.client
;有的只是在 HTTP
。此外,其他的变化是必需的 - 例如,的HttpClient
现在是一个接口,所以你不能实例化它这样。基本上,你有3.X code,所以您应该更新到4.x或使用3.x的jar文件。
Not all the classes which were in httpclient
are now in http.client
; some are just in http
. Additionally, other changes are required - for example, HttpClient
is now an interface, so you can't instantiate it like that. Basically, you've got 3.x code, so you should either update it to 4.x or use the 3.x jar files.
这篇关于阿帕奇HttpClient的不存在。错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!