2016-04-23 11 views
0

私はJsoupを使用してウェブサイトにログインしようとしましたが、残念ながら私はいくつかの問題を強いられました。それの名前。私のコードはどのように見えるのですか?Jsoup:送信ボタンのidまたは名前のないログイン

<form action="http://www.abcde.com/index.php?app=core&amp;module=global&amp;section=login&amp;do=process" method="post" id="login"> 
<input type="hidden" name="auth_key" value="auth_key"> 
<input type="hidden" name="referer" value="http://www.abcde.com/"> 
<h3>Login</h3> 

<div class="ipsForm ipsForm_horizontal"> 
    <fieldset> 
     <ul> 

      <li class="ipsField ipsField_primary"> 
       <label for="ips_username" class="ipsField_title">Username</label> 
       <div class="ipsField_content"> 
        <input id="ips_username" type="text" class="input_text" name="ips_username" size="30" tabindex="0"> 
       </div> 
      </li> 
      <li class="ipsField ipsField_primary"> 
       <label for="ips_password" class="ipsField_title">Password</label> 
       <div class="ipsField_content"> 
        <input id="ips_password" type="password" class="input_text" name="ips_password" size="30" tabindex="0"><br> 
       </div> 
      </li> 

     </ul> 
    </fieldset> 

    <div class="ipsForm_submit ipsForm_center"> 
     <input type="submit" class="ipsButton" value="Login" tabindex="0"> 
    </div> 
</div> 
</form> 

私が開始しました:

Connection.Respose loginForm = Jsoup.connect("http://www.abcde.com/").method(Connection.Method.GET) 
         .execute(); 
    Document document = Jsoup 
         .connect("http://www.abcde.com/) 
         .data("cookieexists", "false") 
         .data("ips_username", "username", "ips_password", 
           "password").cookies(loginForm.cookies()).post(); 
+0

ここをクリックしてください - http://stackoverflow.com/questions/31871801/problems-submitting-a-login-form-with-jsoupおそらくあなたのログイン要求ですべてのパラメータを送信しないでください。 – TDG

+0

私はそれを想定していますが、ビューソースにはviewstateまたはeventvalidationはありません。 – adolzi

+0

これは単なる例でした。ブラウザとサーバーの間のhttpトラフィックを除外するか、到達しようとしている実際のURLを追加する必要があります。ところで、あなたのソースには "auth_key"があります。あなたはどこかでそれを使う必要があると思います。私はこの値がセッション間で変わるとも言います。 – TDG

答えて

0

まずサーバーにGETリクエストを送信する必要があります -

Element e = doc.select("input[id=auth_key]").first(); 
String authKey = e.attr("value"); 
- 次に

Document doc1 = Jsoup.connect("www.forumowisko.pl") 
       .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0") 
       .get(); 

あなたはAUTH_KEY値を抽出します

そして今あなたがすることができますND POST要求 - POST要求がGETリクエストは異なるURLを持っていることを

Document doc2 = Jsoup.connect("http://www.forumowisko.pl/index.php?app=core&module=global&section=login&do=process") 
     .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0")   
     .data("auth_key", authKey)  
     .data("ips_username", "MyUsername") 
     .data("ips_password, "MyPassword") 
     .data("rememberMe", "1") 
     .data("referer", "http://www.forumowisko.pl/") 
     .cookies(doc1.cookies()) 
     .post(); 

注意してください。

+0

私はuserAgentを変更しました。また、doc.select( "input [id = auth_key]")を[name = auth_key]に、doc1.cookies()をresponse.cookies ()とそれは正常に動作します。ご協力ありがとうございます。しかし、もう1つの質問があります。他のURLに適切にリダイレクトしてログに記録する方法を教えてください。パラミスを送信する方法はありますか、そうした方法でこれらのパラーム全体を送信する必要があるたびにですか? – adolzi

+0

私はあなたの質問を理解していません - あなたはログイン後何をしようとしていますか? – TDG

+0

私はクッキーを送ることを意味しましたが、まだ解決しました。もう一度ありがとう – adolzi

関連する問題