The Artima Developer Community
Sponsored Link

Java Answers Forum
Handling Redirects

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Steve Schooler

Posts: 17
Nickname: zugzwang
Registered: Aug, 2004

Handling Redirects Posted: Jul 25, 2006 12:36 PM
Reply to this message Reply
Advertisement
Trying to create java application that will download a file from a website (e.g. www.website1.com). Following excerpt generally works ok.

...
URL u = new URL("http://www.website1.com/filetoget.html")
HttpURLConnection huc = (HttpURLConnection) u.openConnection();
huc.setRequestMethod("GET");
huc.connect();
int code = huc.getResponseCode();
...


Unfortunately, www.website1.com redirects to www.website2.com, so huc.getResponseCode() <above> returns 302 rather than 0. I tried inserting

huc.setRequestProperty("Authorization","Basic myUserID:myPasswd");


but still get 302 rather than 0. How do I supply my UserID/Passwd to handle the redirect?

More generally, I'd like to not have to supply the UserId/Passwd with each GET request. Instead, I want to (somehow) login to website1 or website2 at the start of the app (only). Is this doable?

As a last resort, could I create an applet to download the file. From Firefox, if I login to website1 (thru website2), then any other "tabs" in that Firefox session are "authorized". Any reason why this approach won't work?

Request insights, coding samples, website references...

Topic: Q about expected behavior of FileHandler Previous Topic   Next Topic Topic: socket programing

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use