commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Charles Huey" <>
Subject HELP with HttpClient in downloading a file
Date Tue, 12 Aug 2003 15:54:08 GMT
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");
            InputStream is = oGetFile.getResponseBodyAsStream();
            FileOutputStream fos = new
            int c;
            while(( != -1) {    
        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...


View raw message