Click to See Complete Forum and Search --> : Problem creatingan Inputstream from a URLconnection


Kurapica
11-04-2005, 10:02 AM
Hi, all :)

SORRY ALL- it was my mistake, I should have put "/" before the filename

---------------------------------------------------------------------
>I have a problem creating an InputStream object here is the code :
URL url = new URL("http", "archive.ncsa.uiuc.edu", -1, "SDG/Software/Mosaic/Demo/url-primer.html");
URLConnection urlc = url.openConnection();
urlc.connect();
InputStream input = urlc.getInputStream();


>I get the following exception error:
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 400 for URL: http://archive.ncsa.uiuc.eduSDG/Software/Mosaic/Demo/url-primer.html
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at Url.main(Url.java:9)


>Thnx in advance
-----------------------------------------------------------------

sjalle
11-06-2005, 05:12 PM
It works ok if you write the file spec right, with a leading slash:

URL url = new URL("http", "archive.ncsa.uiuc.edu", -1, "/SDG/Software/Mosaic/Demo/url-primer.html");

btw, it works fine without this statement too:

urlc.connect();