Я обнаружил, что для входа в учетную запись Hotmail требуется всего несколько параметров. вот мой окончательный код:
public void executeParser(String website_url, String emailid,String password) throws Exception
{
//Website url is https://login.live.com/ppsecure/post.srf
String ppft=null;
client.getParams().setParameter(HttpMethodParams.USER_AGENT,
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/8.0 (.NET CLR 3.5.30729)");
client.getParams().setCookiePolicy(org.apache.http.client.params.CookiePolicy.BROWSER_COMPATIBILITY);
GetMethod get_siteurl = new GetMethod(website_url);
client.executeMethod(get_siteurl);
is = get_siteurl.getResponseBodyAsStream();
output = StringFormat.convertStreamToString(is);
get_siteurl.releaseConnection();
Parser parser= new Parser(output);
NodeList nodelist1 = parser.parse(null);
NodeList list1 = nodelist1.extractAllNodesThatMatch(inputfilter , true);
for(int i=0;i<list1.size();i++)
{
Node n=list1.elementAt(i);
if(n.getText().contains("PPFT"))
{
ppft=n.getText();
String s[]=ppft.split("value=");
ppft=s[1];
ppft=ppft.replaceAll("\"","");
ppft=ppft.replaceAll("/","");
break;
}
}
//POST PARAMETERS TO LOGIN TO HOTMAIL ACCOUNT
PostMethod postdata = new PostMethod("https://login.live.com/ppsecure/post.srf");
postdata.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
NameValuePair userid = new NameValuePair("login",emailid);
NameValuePair pwd = new NameValuePair("passwd", password);
NameValuePair type = new NameValuePair("type","11" );
NameValuePair loginoptions = new NameValuePair("LoginOptions", "3");
NameValuePair newuser = new NameValuePair("NewUser","1");
NameValuePair PPFT = new NameValuePair("PPFT",ppft);
//NameValuePair button = new NameValuePair("SI", "Sign in");
NameValuePair[] data = {userid,pwd,type,loginoptions,newuser,PPFT};
postdata.setRequestBody(data);
client.executeMethod(postdata);
is =postdata.getResponseBodyAsStream();
output = StringFormat.convertStreamToString(is);
postdata.releaseConnection();
int statuscode = postdata.getStatusCode();
postdata.releaseConnection();
if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY) ||
(statuscode == HttpStatus.SC_MOVED_PERMANENTLY) ||
(statuscode == HttpStatus.SC_SEE_OTHER) ||
(statuscode == HttpStatus.SC_TEMPORARY_REDIRECT))
{
Header header = postdata.getResponseHeader("Location");
if (header != null)
{
String newuri = header.getValue();
GetMethod redirect = new GetMethod(newuri);
client.executeMethod(redirect);
redirect.releaseConnection();
}
}
GetMethod get = new GetMethod("http://mail.live.com/default.aspx");
get.setFollowRedirects(true);
client.executeMethod(get);
is = get.getResponseBodyAsStream();
output = StringFormat.convertStreamToString(is);
System.out.println("This is the final page after login: "+ output);
}
}