Thanks for replying Niti...
The code is taken straight from the first example in the tutorial. I had only
added a package statement at the top. The GetMethod class is in
httpclient.methods and it's parameter HttpClient in in the httpclient package.
Both packages have their own import statements in the sample code.
Regards
/j-p.
Here's the sample code:
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
import java.io.*;
public class HttpClientTutorial {
private static String url = "http://www.apache.org/";
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.RETRY_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();
}
}
}
Quoting "Niti Bhatt \\(PL/EUS\\)" <[EMAIL PROTECTED]>:
> A very simplest guess, did you import the package in your class file?
>
> -----Original Message-----
> From: John-Paul Delaney [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, March 20, 2007 5:05 PM
> To: [email protected]
> Subject: Newbie: Simple example doesn't compile
>
>
> Hello List...
>
> My first attempt with the tutorial class HttpClientTutorial class
> doesn't compile. I've added the http client jar to the classpath but
> get the following error when trying to compile:
>
> HttpClientTutorial.java:26: cannot resolve symbol symbol : method
> executeMethod (org.apache.commons.httpclient.HttpMethod)
> location: class com.justatest.test.HttpClientTutorial
> int statusCode = client.executeMethod(method);
> ^
> 1 error
>
> Has anyone experienced this? Even explicitly adding the jarfile to the
> classpath in the javac commandline doesn't help.
>
> thanks for any suggestions
> /j-p.
>
>
> ------------------------------------------------------------------------
> ---
> Open Invitation for Contemporary Visual Artists.
> http://www.artprocess.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------------
Open Invitation for Contemporary Visual Artists. http://www.artprocess.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]