HTTP File Access with Java

U

uri

Is it possible to access HTTP files in a Java App (not applet)? What
about if the website is secure (i.e. requires a password) but I have
the password/login? What about in cases where the file must be chosen
from a dropdown list?

Is this the list to post this type of question to?

Thanks in advance,
--Uri
 
S

Simon OUALID

uri said:
Is it possible to access HTTP files in a Java App (not applet)? What
about if the website is secure (i.e. requires a password) but I have
the password/login? What about in cases where the file must be chosen
from a dropdown list?

All is done by the URL class.

http://java.sun.com/j2se/1.5.0/docs/api/java/net/URL.html

URL url = new URL(myURLString);
InputStream is = url.openConnection().getInputStream();

Then use it as a normal stream, by associating it to a FileOutputStream
if you want to download the file on the file system.

I think (but I'm not sure) that HTTPS connection are handled by this
class. If you need authentification, you can ovveride the Authenticator
class and the getPasswordAuthentication() method.

http://java.sun.com/j2se/1.5.0/docs/api/java/net/Authenticator.html

Symon
 
E

enrique

I guess so. When accessing a remote file with HTTP, that doesn't seem
different from what a browser would do, right? So design your Java App
to behave like a browser, when it needs to interact with the website.
 
R

Roedy Green

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top