Results 1 to 5 of 5
Thread: Using HttpClient with Eclipse
- 01-06-2010, 08:36 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 5
- Rep Power
- 0
Using HttpClient with Eclipse
I was recently told that I should be using HttpClient to solve a particular problem I was working on. I've never used it before, and have a lot to learn about it, but before I can start I need to download it.
And embaressingly enough thats where I'm stuck.
I went the download page at the httpclient site (wont let my put link here)
and "right click- save as" the .zip file under binary with dependencies. I extracted it into a project file, and then tried to run the sample code:
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodPar ams;
import java.io.*;
public class HttpClientTutorial {
private static String url = "website"; //website instead of a real website,
//cause i cant post links
public static void main(String[] args) {
// Create an instance of HttpClient.
HttpClient client = new HttpClient();
// Create a method instance.
GetMethod method = new GetMethod(url);
// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.R ETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
try {
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
// Read the response body.
byte[] responseBody = method.getResponseBody();
// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
System.out.println(new String(responseBody));
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}
}
}
I got this error in the console -
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
HttpClient cannot be resolved to a type
HttpClient cannot be resolved to a type
GetMethod cannot be resolved to a type
GetMethod cannot be resolved to a type
HttpMethodParams cannot be resolved
DefaultHttpMethodRetryHandler cannot be resolved to a type
HttpStatus cannot be resolved
HttpException cannot be resolved to a type
at Test.main(Test.java:14)
When hovering over my import statements it tells me that the imports can't be resolved.
Any ideas what I'm doing wrong? I assume the .jars are in the wrong place? The website also had something about "verify the integrity of the downloaded files using signatures downloaded from our main distribution directories." and "The KEYS link links to the code signing keys used to sign the product. The PGP link downloads the OpenPGP compatible signature from our main site. The MD5 link downloads the checksum from the main site. " which I honestly don't know what means.
Anyways, I'm sure there are some serious flaws in my logic here, but any guidance would be greatly appreciated, I'm a beginner struggling to find a place to start learning.
- 01-06-2010, 08:44 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
The jars containing those classes need to be added to the classpath when you compile (and run) the program.
Setting the class path
- 01-06-2010, 09:26 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 5
- Rep Power
- 0
Hmmm... I checked the .classpath file in the project folder and they're definately in it. Could it be anything else? What does it mean for some classes to be dependencies?
- 01-06-2010, 09:29 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 01-06-2010, 09:47 AM #5
Member
- Join Date
- Jan 2010
- Posts
- 5
- Rep Power
- 0
Actually, when opening the jars none of them had a httpclient inside a commons folder, which is confusing, because I downloaded this directly from the httpclient site, and theres even a quickstart page that lists which .jar files should be included.
Is it possible this has something to do with the "verify the integrity of the downloaded files using signatures downloaded from our main distribution directories" statement on the download page? What does that mean?
Similar Threads
-
Getting httpclient working with eclipse.
By int80 in forum EclipseReplies: 4Last Post: 03-31-2009, 01:17 PM -
HttpClient invalid headers
By Nicole in forum Advanced JavaReplies: 6Last Post: 03-31-2009, 12:36 AM -
[SOLVED] Putting HttpClient and dependencies on classpath
By dan0 in forum EclipseReplies: 1Last Post: 03-13-2009, 09:10 PM -
Is it possible to run eclipse plugins without using eclipse?
By ambar in forum EclipseReplies: 2Last Post: 01-27-2009, 02:10 PM -
Eclipse Bug - Can't Read From A File Using Eclipse?
By carlodelmundo in forum New To JavaReplies: 6Last Post: 01-26-2009, 04:25 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks