Apache httpclient does not exist. error

Hi, I keep getting errors 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 

for compilation I used

 javac -cp ;./httpclient-4.2.jar;jsoup-1.6.3.jar test.java 

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(); } 

I am very confused and do not know what I am doing wrong. I think this is simple, but I checked several times and it exists and jsoup compiles fine. Thanks

+4
source share
3 answers

I believe you want org.apache.http.client if you are using HttpClient 4.2 (which it looks like you are). The org.apache.commons.httpclient package is for the old version .

EDIT: not all classes located in httpclient are now in http.client ; some of them are only in http . In addition, other changes are required - for example, httpclient now an interface, so you cannot create it this way. Basically, you have 3.x code, so you need to either upgrade it to 4.x or use 3.x flag files.

+8
source

use jar -xvf httpclient-4.2.java temp

check if org / apache / commons / httpclient / cookie exists, if not then this is incorrect / damaged jar

Also try javac -cp.; ./ httpclient-4.2.jar; jsoup-1.6.3.jar test.java instead of javac -cp; ./ httpclient-4.2.jar; jsoup-1.6.3.jar test.java

0
source

I found my missing version from here: http://mvnrepository.com/artifact/commons-httpclient/commons-httpclient

 dependencies { compile 'commons-httpclient:commons-httpclient:3.1' } 
0
source

All Articles