Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / July 2005

Tip: Looking for answers? Try searching our database.

Http

Thread view: 
freesoft_2000@yahoo.com - 13 Jul 2005 13:50 GMT
Hi everyone,

                  I am currently trying to do an application that does
the upload as well the download of files from a http server that needs
authentication.
The thing is i am not very sure where to begin and i am open to any
suggestions.

                  Basically what i am trying to upload is a html file
onto the  http server and also have the capability to download back
that file back to my computer if i need it. The server i am using does
not support ftp so using the sun's ftp classes are out but i am not
sure if there are classes that exist for the uploading and downloading
of files from a http server.

                 I am not using servlets but trying to upload or
download a simple html file to http server from a java application

                 Sample codings as well as informative links would be
helpfull

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
Chris Smith - 13 Jul 2005 15:05 GMT
>                    Basically what i am trying to upload is a html file
> onto the  http server and also have the capability to download back
> that file back to my computer if i need it. The server i am using does
> not support ftp so using the sun's ftp classes are out but i am not
> sure if there are classes that exist for the uploading and downloading
> of files from a http server.

There are classes in the Java API that support communicating with an
HTTP server.  They are java.net.URL and java.net.HttpURLConnection.  See
the javadocs for details.  Basically, you create a URL, call its
openConnection method, and cast the result to an HttpURLConnection do do
do HTTP-specific stuff.

There are limits to the capabilities of these standard API classes.  If
you need more functionality, a fuller interface, or any of a few dozen
other things that HttpURLConnection doesn't provide, then the Jakarta
Commons HttpClient package will probably do what you want.  Get it from
jakarta.apache.org and see the documentation on that site.  (And, of
course, come back if you have specific problems.)

That leaves the question of whether HTTP alone can do what you want
anyway.  Theoretically, it can.  HTTP's GET method will retrieve a file,
and its PUT method will upload a file.  That said, though, the number of
HTTP servers that actually implement the PUT method is negligible, and
doing things this way is extremely unlikely to work.  It's more likely
that you need to figure out exactly how you're expected to upload files,
and let us know that information before we'll ave any clue how you might
upload files to the web site.  You've said it's not FTP, and it's very
unlikely to be plain HTTP PUT requests.  Is it FrontPage extensions?  
Something else?

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

freesoft_2000@yahoo.com - 14 Jul 2005 12:46 GMT
Hi everyone,

            I am basically trying to upload a html file or download a
html file to or from a http address. The thing is that i have been
reading up on some http and it seems that i can use the URLConnection
class to get the ouput or input stream from that http address but the
thing is it does not say how do i authenticate(ie. username and
password) before i can connect to that particular http server. Do you
know how this can be achieved??

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
Chris Smith - 14 Jul 2005 14:26 GMT
>              I am basically trying to upload a html file or download a
> html file to or from a http address. The thing is that i have been
[quoted text clipped - 3 lines]
> password) before i can connect to that particular http server. Do you
> know how this can be achieved??

First, please read my earlier reply.  There is a vanishly small
percentage of HTTP servers that actually allow uploading HTML files via
a PUT request.  The overwhelming probability is that your server isn't
going to implement this, and your efforts in that direction will fall.  
You've yet to tell us how you would upload files by hand to this server.  
What application would you use to do this?

Nevertheless, if you wish to give it a shot your way, then read on.  To
specify authentication information for java.net.URL and its related
classes, you need to use the java.net.Authenticator class.  You will
subclass Authenticator and override getPasswordAuthentication().  Then
call Authenticator.setDefault to install your authenticator for use with
all URL instances.  (There unfortunately seems to be no way to do this
for just one connection.)

IIRC, Java's HttpURLConnection only implements basic authentication.  It
definitely will not do NTLM.  If you need more options then look again
at Jakarta HttpClient.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

freesoft_2000@yahoo.com - 14 Jul 2005 15:45 GMT
Hi everyone,

             Sorry Chris i forgot to mention that the http server is
using the PUT command for uploading and GET command for downloading

             From what you are saying this is what i understand
say for example if my username w and password is w1
so to use the class this what i would have to do

public class con
{
pl Auth;
Auth.setDefault(Auth);
URL url = new URL("http://www.pol.com");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
//rest of code
}

public class pl extends Authenticator
{

protected PasswordAuthentication getPasswordAuthentication()
{
String name = "w";
Char[] pass = {"w", "1");
PasswordAuthentication Pras = new PasswordAuthentication(name, pass);

return Pras;
}

}

My problem is now when do i know when i need to authenticate. I do not
know if the class con which i have above which sets the default
authenticator is correct before i try to connect to that URL and get
its stream and would really appreciate some guidance from you.

Is there a way in which i can know if a particular URL requires
authentication before connecting to it??

Some sample codings would really be helpfull

Thank You

Your Sincerely

Richard West


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.