Dave Ray's answer is really quick and simple, but it will not work with HTTP redirects or if, for example, you have to go through a proxy server that requires authentication. Unfortunately, the standard Java API classes (in java.net) do not have some functionality or are difficult to use in such circumstances.
The open source Apache HttpClient library can automatically handle redirects and simplify work with proxies that require authentication.
Here is a basic example:
HttpClient client = new HttpClient(); GetMethod method = new GetMethod("http://www.abc.com/file.xml"); int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } byte[] responseBody = method.getResponseBody();
Jesper
source share