Is there no one out there who knows anything about HttpClient? I can't
figure out how to download a file using this thing. Before the following
code, I successfully manage to log into an HTTPS site and submit another
form to get a listing of data files ready for download, and after that
POST, I can get the HTML from the file listing using
getResponseBodyAsString(), so from there I parse out the URLs I need and
pass them on to my downloadFiles() method--which currently only tries to
do this with one URL and file:
private void downloadFiles(String toDownload) {
GetMethod oGetFile = new GetMethod(toDownload);
try { oClient.executeMethod(oGetFile); }
catch(HttpException e) {e.printStackTrace(); }
catch(IOException e) {e.printStackTrace(); }
System.out.println(oGetFile.getStatusCode() + " : " +
oGetFile.getStatusText() + " \n\n");
oGetFile.releaseConnection();
try
{
InputStream is = oGetFile.getResponseBodyAsStream();
FileOutputStream fos = new
FileOutputStream("c:\\downloaded");
int c;
while((c=is.read()) != -1) {
fos.write(c);
}
is.close();
fos.flush();
fos.close();
}
catch (FileNotFoundException fnfe) { System.out.println("FNFE:
"+fnfe.toString()); }
catch (IOException ioe) { System.out.println("IOE:
"+ioe.toString()); }
catch (NullPointerException e) { System.out.println("NPE: " +
e.toString()); }
}
The above code returns 200 : OK from getStatusCode and getStatusText, but
then it throws a NullPointerException when I get to the while statement.
There is definitely some data in this file, so why am I getting a
NullPointerException??? Or is there some other way to try to download a
file? Thanks so much in advance...
Stephen
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]