HTTP redirect?
Hello all,
Im making a simple app that will fill out a login form to login to Yahoo! on their https://login.yahoo.com server. Then, I am trying to get it to redirect me to one of their game room servers. However, I keep getting a page that says, "your browser doesnt support redirects..." something along those lines. But if I open my browser and type in the proper link ( which I am trying to simulate using this app ) everything works.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.CookieHandler;
import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
publicclass Main
{
privatestaticfinal String LOGIN_SERVER ="https://login.yahoo.com";
privatestaticfinal String GAMES_SERVER ="http://games.yahoo.com";
privatestaticfinal String GAME_ROOM ="/games/ante?room=pool_aa&prof_id=chat_pf_1&nosignedcab=yes;
privatestaticfinal String NEW_REDIRECT ="&.done=" + GAME_SERVER + GAME_ROOM;
private String packet;
private ArrayList< String > hiddenInfo;
public Main( String userName, String password )
{
/* CookieManager is an API i got from a website about grabbing
and storing cookies from a connection header. Assume anything
it does is correct.
*/
CookieManager cm =new CookieManager ();
hiddenInfo =new ArrayList<String>();
try
{
URL url =new URL ( LOGIN_SERVER );
HttpURLConnection conn = (HttpURLConnection)url.openConnection ();
// Gets the "Set-Cookie" header and stores it
cm.storeCookies (conn);
/* Get the lines of the html code that contain hidden input fields
and stores them in the hiddenInfo arrayList.
*/
getHiddenInfo (conn);
//Takes the hidden fields and parses them into name=value pairs.
parseData ();
/* Sets the 'packet' to contain a url with all of the hidden items
along with the users name and password. A sample packet
would look like this:
"config/login?.tries=1&.src=&.md5=&.hash=&.js=&.last=&promo=
&.intl=us&.bypass=&.partner=&.u=7ti7tg93adntj&.v=0&
.challenge=Z7VIm0YWQyWL2yZ2I.GIn0HLGd_d&.yplus=&.emailCode=
&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&.done=http://my.yahoo.com
&.pd=_ver%3d0%26c=&login=" + yahooID + "&passwd=" + password
+"&.persistent=y"
*/
buildLoginPacket ( yahooID, password );
//Now replace the default redirect with my own
packet = packet.replaceAll ("&.done=http://my.yahoo.com", NEW_REDIRECT );
//Try connecting to the new URL to login and go to the game room.
url =new URL ( LOGIN_SERVER +"/"+ packet );
conn = (HttpURLConnection)url.openConnection ();
conn.setFollowRedirects(true );
/*Set the cookies previously stored or else yahoo sends
you right back to the login page.
*/
cm.setCookies (conn);
//Open an inputstream and print out the reply from the server.
outputResult( conn );
}
catch (IOException ioe)
{
ioe.printStackTrace ();
}
}
}
The server always returns this Page:
<html>
<head>
<script language="JavaScript">
<!--
window.location.replace("http://games.yahoo.com/games/ante?room=pool_aa");
// -->
</script>
<meta http-equiv="Refresh" content="0; url=http://games.yahoo.com/games/ante?room=pool_aa">
</head>
<body>
If you are seeingthis page, your browser settings prevent you
from automatically redirecting to anew URL.
Please <a href="http://games.yahoo.com/games/ante?room=pool_aa">click here</a> to continue.
</body>
</html>
Any ideas to get the redirect?

