aspose file tools*
The moose likes Beginning Java and the fly likes URLs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "URLs" Watch "URLs" New topic
Author

URLs

Richard West
Ranch Hand

Joined: Jan 07, 2005
Posts: 127
Hi everyone,

I have actually two questions on the following link at another forum but i am not getting any responses from it. Maybe someone can have a look at the link and post any responses here.

Here is the link

http://forums.devshed.com/t277542/s.html

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
Richard West
Ranch Hand

Joined: Jan 07, 2005
Posts: 127
Hi everyone,

Sorry about only leaving a link. I got an e-mail from someone saying that its better if i posted thge question here than they going back forth. Anyways here are the two questions

I have two rather silly questions about URLs but please bear with me for a while.

Usually when you use the URLConnection class to read from a website you don't get prompted for authentication but if you are trying to post something to that website you will usually require some kind of authentication.

Please assume that the authenticator class has been set correctly and that its getPasswordAuthentication() method returns the correct username and passsword

Consider this code



My problem is now i do not know that if i am going to post to that website(and it most certainly will need authentication) will i be prompted by the Authenticator class so i can get the outputstream and post to that website

I am not able to test this code because i currently do not have any website to post to but i am working on an application that could possibly do this.

On another question lets say i am reading from a website that has a zip file say www.yahoo.com/my_life_story.zip

Now if i do this am i right??



Now in above code i am reading stream bytes but if i were using the PrintReader and putting the output to the console you would see all the server html commands and the byte content of the file but as rubbish text.

Now basically my question is when i read that file as stream bytes and save it to disk will all the html commands also be saved because that's not what i want. I only want the zip file.

I hope someone can help me with the above two questions

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

You should consider using Jakarta HttpClient. It offers a simple-to-use API that can handle file downloads and HTTPS.
Richard West
Ranch Hand

Joined: Jan 07, 2005
Posts: 127
Hi everyone,

I can't use the Jakarta HttpClient because i need something that uses the Java URL class. I know it sounds stupid but at this point of time i really have keep things simple.

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

If you don't want to use any other libraries, you'll need to roll your own parser to handle the servlet response. What questions do you have about how to do this?
Richard West
Ranch Hand

Joined: Jan 07, 2005
Posts: 127
HI everyone,

Steve currently i may start to roll out my own parser but before i can start i need to know how the Java URL class handles its url ouputstream and inputstream.

First do the streams if read as bytes include only the content of the website??

or

does it include the servers response together withe the content of the website??

Steve please consider the below code



Now my question is when i read that file as stream bytes and save it to disk will all the server commands also be saved because that's not what i want. I only want the zip file.

Did you experience such thing before when you tried to download any file from a url using the URL class with java while getting its stream??

If you did is there a way to overcome it??

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: URLs