2012-12-02 7 views
1

방금 ​​HtmlUnit을 시작했으며 Javascript를 사용하는 sHttp 페이지에 로그인하고 싶습니다. 문제입니까? 아니,하지만 로그인 할 수 없으면 좋겠어. 문제가 어디 있니? 적어도 로그인 실패로 경고해야하지만 로그인 시도가 없었던 것처럼 보입니다. 모든 아이디어에 대해 감사드립니다. 여기 HtmlUnit/Java를 통해 로그인 할 수 없습니다.

WebClient webClient = new WebClient(); 
//webClient.setJavaScriptEnabled(true); 
//webClient.getCookieManager().setCookiesEnabled(true); 


// Get the first page 
HtmlPage page1 = (HtmlPage) webClient.getPage("http://goo.gl/AxhP8"); 
HtmlPage page2 = (HtmlPage) page1.getFrameByName("text").getEnclosedPage(); 

// Get the form that we are dealing with and within that form, 
// find the submit button and the field that we want to change. 
HtmlForm form = page2.getFormByName("login"); 

// Enter login and passwd 
form.getInputByName("xlogin").setValueAttribute("login"); 
form.getInputByName("xpasswd").setValueAttribute("password"); 


// Click "Sign In" button/link 
page1 = (HtmlPage) form.getInputByValue("Přihlásit").click(); 

// Get page as Html 
String htmlBody = page1.getWebResponse().getContentAsString(); 
// Save the response in a file 
String filePath = "test_out.html"; 

BufferedWriter bw = new BufferedWriter(new FileWriter(new File(filePath))); 
bw.write(htmlBody); 
bw.close(); 

webClient.closeAllWindows(); 

양식 (또는 당신이 여기 소스를 얻을 수 있습니다 : http://goo.gl/AxhP8를)

<form action="/fcgi/verso.fpl" method="GET" name="login" onsubmit="wipRet=true;wipRet=true;wipRet=kontrola_hesla(this);if(wipRet==false){wipRet=false;}else{vrGetScrollTop(this);doWkinPrgs(this.target,'Probíhá přihlášení uživatele ...');};if(wipRet==false){return false;}else{vrGetScrollTop(this);doWkinPrgs(this.target,'');}" target="text"> 
<input name="_vr_sclt" type="hidden" value="0" /> 
<input name="_vr_sclt" type="hidden" value="0" /> 
<input id="fname" name="fname" type="hidden" value="neni_js" /> 

Uživatel: <input class="login_in" name="xlogin" size="15" type="text" /> 
Heslo: <input class="login_in" name="xpasswd" size="15" type="Password" /> 
<input class="btn" type="submit" value="Přihlásit" width="50" /> 

<input name="__formid" type="hidden" value="2a620f43d0478d14" /> 
<input name="__idf" type="hidden" value="afc09868294ba6ac" /> 
<input name="__formid" type="hidden" value="f73fa3ddfe457bc1" /> 
<input name="__idf" type="hidden" value="3162299a379cf323" /> 

</form> 

덕분에 모든 작은 도움을, 나는 많은 기사를 읽고 내가 움직일 수 아니에요, 몇 시간을 보냈다 앞으로, thx :) 쿠키 또는 그런 것에 문제가 있습니까?

답변

0
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6); 
파이어 폭스의이 IE보다 훨씬 더 ...

:이 // 지금 작동

관련 문제