java에서 httpclient로 hotmail 계정에 로그인하고 싶습니다. 다음은 내 코드입니다. 파이어 폭스에 "탬퍼 데이터"추가 기능을 사용하여 post 메서드와 함께 전달할 매개 변수 목록을 찾았습니다. hotmail은 javascript를 사용하고 있으므로 post 메소드와 함께 전달되는 몇 가지 매개 변수의 값을 가져올 수 없습니다. 아무도 여기서 나를 도와 줄 수 없나요? 저도 같은 페이지로 데려 가고 있습니다. post 메소드에 의해 반환 된 상태 코드는 200 OK입니다. 이는 리다이렉션 중임을 의미합니다.java에서 httpclient로 Hotmail 계정에 로그인
정말 도움이됩니다.
감사합니다.
Ragini
public void executeParser(String website_url, String emailid,String password) throws Exception
{
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);
//System.out.println(output);
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("/","");
//System.out.println(ppft);
break;
}
}
//POST PARAMETERS TO LOGIN TO HOTMAIL ACCOUNT
PostMethod post_uname_pwd = new PostMethod("https://login.live.com/ppsecure/post.srf");
post_uname_pwd.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 mest = new NameValuePair("MEST", "");
NameValuePair idsbho = new NameValuePair("idsbho", "1");
NameValuePair pwdpad = new NameValuePair("PwdPad", "");
NameValuePair PPFT = new NameValuePair("PPFT",ppft);
NameValuePair sso = new NameValuePair("sso", "");
NameValuePair i1 = new NameValuePair("i1", "");
NameValuePair i2 = new NameValuePair("i2", "1");
NameValuePair i4 = new NameValuePair("i4","");
NameValuePair i12 = new NameValuePair("i12","1");
NameValuePair i13 = new NameValuePair("i13","");
NameValuePair i17 = new NameValuePair("i17", "");
NameValuePair button = new NameValuePair("SI", "Sign in");
NameValuePair[] data = {userid,pwd,type,loginoptions,newuser,mest,idsbho,pwdpad,PPFT,sso,i1,i2,i4,i12,i13,i17,button};
//post_uname_pwd.getParams().setCookiePolicy(org.apache.http.client.params.CookiePolicy.BROWSER_COMPATIBILITY);
post_uname_pwd.setRequestBody(data);
client.executeMethod(post_uname_pwd);
is = post_uname_pwd.getResponseBodyAsStream();
output = StringFormat.convertStreamToString(is);
System.out.println(output);
//post_uname_pwd.releaseConnection();
int statuscode = post_uname_pwd.getStatusCode();
post_uname_pwd.releaseConnection();
System.out.println(statuscode);
if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY) ||
(statuscode == HttpStatus.SC_MOVED_PERMANENTLY) ||
(statuscode == HttpStatus.SC_SEE_OTHER) ||
(statuscode == HttpStatus.SC_TEMPORARY_REDIRECT))
{
Header header = post_uname_pwd.getResponseHeader("Location");
System.out.println("Header is : " + header.getValue());
if (header != null)
{
String newuri = header.getValue();
//System.out.println("Redirect target after Post: " + newuri);
GetMethod redirect = new GetMethod(newuri);
client.executeMethod(redirect);
is = redirect.getResponseBodyAsStream();
output = StringFormat.convertStreamToString(is);
System.out.println(output);
redirect.releaseConnection();
}
}
}
핫메일! 오, 세상에, 심지어 그 존재를 잊어 버렸습니다 ... 추억의 차선에서 내려 주셔서 감사합니다. – gnomed
"type", "LoginOptions", "NewUser"매개 변수는 실제로 선택 사항입니다. –