The following are the values I use, maybe u can crosscheck?
nvPairs.add(new NameValuePair("login", userName));
nvPairs.add(new NameValuePair("passwd", password));
nvPairs.add(new NameValuePair(".tries","1"));
nvPairs.add(new NameValuePair(".src","ym"));
nvPairs.add(new NameValuePair(".md5",""));
nvPairs.add(new NameValuePair(".hash",""));
nvPairs.add(new NameValuePair(".js",""));;
nvPairs.add(new NameValuePair(".last",""));
nvPairs.add(new NameValuePair("promo",""));
nvPairs.add(new NameValuePair(".intl","us"));
nvPairs.add(new NameValuePair(".bypass",""));
nvPairs.add(new NameValuePair(".partner",""));
nvPairs.add(new NameValuePair(".u",u));
nvPairs.add(new NameValuePair(".v","0"));
nvPairs.add(new NameValuePair(".challenge",challenge));
nvPairs.add(new NameValuePair(".yplus",""));
nvPairs.add(new NameValuePair(".emailCode",""));
nvPairs.add(new NameValuePair("pkg",""));
nvPairs.add(new NameValuePair("stepid",""));
nvPairs.add(new NameValuePair(".ev",""));
nvPairs.add(new NameValuePair("hasMsgr","0"));
nvPairs.add(new NameValuePair(".chkP","Y"));;
nvPairs.add(new NameValuePair(".done","http://mail.yahoo.com"));
nvPairs.add(new NameValuePair("persistent",""));
nvPairs.add(new NameValuePair(".hash","1"));
nvPairs.add(new NameValuePair(".md5","1"));
HTH
Regards,
Jaya.
-----Original Message-----
From: Christopher Valorose [mailto:[EMAIL PROTECTED]
Sent: Thursday, November 10, 2005 12:01 AM
To: [email protected]
Subject: Using HTTPClient to login to Yahoo Briefcase
Hello,
I am attempting to use HTTPClient to login into Yahoo.
No matter what I do I keep getting the Yahoo logon page again. See code
below. Any examples or help is greatly appreciated.
public boolean formLoginYahoo( String user, String password){
boolean bFormLogin = false;
String url = "https://login.yahoo.com";
int port = 443;
_client = new HttpClient();
_client.getHostConfiguration().setHost(url,
port, "https");
_client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY);
GetMethod authget = new GetMethod(url);
try{
_client.executeMethod(authget);
}
catch (IOException i){
i.printStackTrace();
}
System.out.println("Login form get: " +
authget.getStatusLine().toString());
// Read the response body.
byte[] responseBody = authget.getResponseBody();
_strGetRspBody = authget.getResponseBodyAsString();
_logger.logDebug("GetRspBody: " + _strGetRspBody);
// release any connection resources used by the method
authget.releaseConnection();
//Get the .u value
int intUStart = _strGetRspBody.indexOf("<input
type=\"hidden\" name=\".u\"");
intUStart = intUStart + 38;
String strU = _strGetRspBody.substring(intUStart,
intUStart + 13);
_logger.logDebug("U value from Get: " + strU);
//Get the .challenge value
int intChallengeStart =
_strGetRspBody.indexOf("<input type=\"hidden\"
name=\".challenge\"");
intChallengeStart = intChallengeStart + 46;
String strChallenge =
_strGetRspBody.substring(intChallengeStart,
intChallengeStart + 28);
_logger.logDebug("Challenge value from Get: " +
strChallenge);
NameValuePair tries = new
NameValuePair("action",
"login");
NameValuePair src = new NameValuePair("url",
"/index.html");
NameValuePair md5 = new
NameValuePair(".md5", "");
NameValuePair hash = new
NameValuePair(".hash",
"");
NameValuePair js = new
NameValuePair(".js", "");
NameValuePair last = new
NameValuePair(".last",
"");
NameValuePair promo = new
NameValuePair("promo",
"");
NameValuePair intl = new
NameValuePair(".intl",
"us");
NameValuePair bypass = new NameValuePair(".bypass",
"");
NameValuePair partner = new
NameValuePair(".partner", "");
NameValuePair u = new
NameValuePair(".u", strU);
NameValuePair v = new
NameValuePair(".v", "0");
NameValuePair challenge = new
NameValuePair(".challenge", strChallenge);
NameValuePair yplus = new
NameValuePair(".yplus",
"");
NameValuePair emailCode = new
NameValuePair(".emailCode", "");
NameValuePair pkg = new
NameValuePair("pkg", "");
NameValuePair stepid = new NameValuePair("stepid",
"");
NameValuePair ev = new
NameValuePair(".ev", "");
NameValuePair hasMsgr = new NameValuePair("hasMsgr",
"0");
NameValuePair chkP = new
NameValuePair(".chkP",
"Y");
NameValuePair done = new
NameValuePair(".done",
"https://my.secure.yahoo.com");
NameValuePair username = new
NameValuePair("username", user);
NameValuePair passwd = new
NameValuePair("passwd", password);
NameValuePair[] valuePairs = {tries, src, md5, hash, js,
last, promo, intl,
bypass, partner, u, v, challenge, yplus, emailCode,
pkg, stepid, ev, hasMsgr, chkP, done, username, passwd};
String strLogonUrl =
"https://login.yahoo.com/config/login?";
PostMethod authpost = new
PostMethod(strLogonUrl);
// Prepare login parameters
authpost.setRequestBody( valuePairs );
try{
_client.executeMethod(authpost);
}
catch (IOException i){
i.printStackTrace();
}
String strStatusLine =
authpost.getStatusLine().toString();
System.out.println("Login form post: " + strStatusLine);
_strPostRspBody =
authpost.getResponseBodyAsString();
_logger.logDebug("Response Body from Post: \n" +
_strPostRspBody);
// release any connection resources used by the method
authpost.releaseConnection();
if (strStatusLine.equals(_success1_1))
bFormLogin = true;
// See if we got any cookies
// The only way of telling whether logon succeeded is
// by finding a session cookie
Cookie[] logoncookies =
_client.getState().getCookies(url, port, "/", false);
System.out.println("Logon cookies:");
if (logoncookies.length == 0) {
System.out.println("None");
} else {
for (int i = 0; i < logoncookies.length;
i++) {
System.out.println("- " +
logoncookies[i].toString());
}
}
// Usually a successful form-based login results in a redicrect
to
// another url
int statuscode = authpost.getStatusCode();
if ((statuscode ==
HttpStatus.SC_MOVED_TEMPORARILY) ||
(statuscode ==
HttpStatus.SC_MOVED_PERMANENTLY) ||
(statuscode == HttpStatus.SC_SEE_OTHER) ||
(statuscode ==
HttpStatus.SC_TEMPORARY_REDIRECT)) {
Header header =
authpost.getResponseHeader("location");
if (header != null) {
String newuri = header.getValue();
if ((newuri == null) ||
(newuri.equals(""))) {
newuri = "/";
}
System.out.println("Redirect target: "
+ newuri);
GetMethod redirect = new GetMethod(newuri);
try{
_client.executeMethod(redirect);
}
catch (IOException i){
i.printStackTrace();
}
System.out.println("Redirect: " +
redirect.getStatusLine().toString());
// release any connection resources used by the method
redirect.releaseConnection();
} else {
System.out.println("Invalid redirect");
System.exit(1);
}
}
return bFormLogin;
}// end class
Thanks in advance
Chris
Thanks
Christophr Valorose
Office: 757-249-7174
Home: 757-565-0883
Cell: 757-784-0789
__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
*********************************************************
Disclaimer:
The contents of this E-mail (including the contents of the enclosure(s) or
attachment(s) if any) are privileged and confidential material of MBT and
should not be disclosed to, used by or copied in any manner by anyone other
than the intended addressee(s). In case you are not the desired addressee,
you should delete this message and/or re-direct it to the sender. The views
expressed in this E-mail message (including the enclosure(s) or attachment(s)
if any) are those of the individual sender, except where the sender expressly,
and with authority, states them to be the views of MBT.
This e-mail message including attachment/(s), if any, is believed to be free of
any virus. However, it is the responsibility of the recipient to ensure that
it is virus free and MBT is not responsible for any loss or damage arising in
any way from its use
*********************************************************
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]