gpt4 book ai didi

java - Apache http客户端不存在。错误

转载 作者:搜寻专家 更新时间:2023-10-31 19:34:30 26 4
gpt4 key购买 nike

嗨,我总是收到错误 enter image description here

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

这是代码

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 编译得很好。谢谢

最佳答案

如果您使用 HttpClient 4.2,我相信您需要 org.apache.http.client (看起来像你)。 org.apache.commons.httpclient 包用于 older version .

编辑:所有httpclient 中的类现在都在http.client 中;有些只是在 http 中。此外,还需要进行其他更改 - 例如,HttpClient 现在是一个接口(interface),因此您不能像那样实例化它。基本上,您有 3.x 代码,因此您应该将其更新到 4.x 或使用 3.x jar 文件。

关于java - Apache http客户端不存在。错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10986661/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com