2012-04-30 9 views
1

minecraft.net用のユーザー名マイグレーションをモディファイドにしようとしているため、アカウントのクラッキングを防ぐためにアカウントを移行できます。そのためには、ウェブサイトにフォームを投稿する必要があります。私は正常にCookieを取得することができますので、authenticityTokenは同じままですが、サイトにデータをポストしようとすると、java.io.IOExceptionがスローされます。URLをロードしようとするとリダイレクトが多すぎますhttps://account.mojang.com/migrateJS例外がIO例外をスローする:URLをロードしようとするとリダイレクトが多すぎる

私は本当になぜこれが起こっているのか分かりませんが、ウェブサイトと関係があるかもしれません。 authentityTokenは確実に一致します。私はサイトに投稿して同じクッキーを提供しないときにこれをチェックしました。ここで私は現在、すべての任意の助けを大幅に

答えて

0

HttpConnection.Responceいただければ幸いです

try { 
     Response response = Jsoup.connect("https://account.mojang.com/migrate").execute(); //downloads site to get the cookies 
     String auth = response.body(); 
     String auth2 = auth.split("name=\"authenticityToken\" value=\"")[1]; 
     auth = auth2.split("\">")[0]; 
     Map<String, String> cookies = response.cookies(); 
     Connection connection = Jsoup.connect("https://account.mojang.com/migrate").data("action", "/migrate/check") 
       .data("authenticityToken", auth) 
       .data("mcusername", "username") 
       .data("password", "password") 
       .method(Method.POST) 
       .followRedirects(true); 
     for (Entry<String, String> cookie : cookies.entrySet()) { 
      connection.cookie(cookie.getKey(), cookie.getValue()); 
     } 
     connection.execute(); //exception thrown here 
     Document document = connection.get(); 
     String docHtml = document.html(); 
     System.out.println(docHtml); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

を使用していたコードは20 あなたの実行は、この制限を超え、そうにIOExceptionがスローされたに等しいMAX_REDIRECTS定数を持っています。

リダイレクトの無限ループで接続が滞っているようです。データを転記する方法を変更してみてください。

EDIT リダイレクト後のすべての新しいページに302のステータスコードがあります。だから問題は多分あなたの要求です。

+0

奇妙なことに、私はリダイレクトループが発生していません。彼の要求は間違っていましたが、「私のためには404だけです。 –

1
final Response response = 
    Jsoup.connect("https://account.mojang.com/migrate").execute(); 
// parse the response as a document, so that we can extract stuff 
final Document doc = response.parse(); 
// correct way to extract parsed html 
final Element authToken = doc.select("input[name^=authenticityToken]").get(0); 
final Map<String, String> cookies = response.cookies(); 
// action isn't part of the querystring. The form POST URL is our target. 
final Connection connection = 
     Jsoup.connect("https://account.mojang.com/migrate/check") 
      .data("authenticityToken", authToken.val()) // correct way to extract val 
      .data("mcusername", "username") 
      .data("password", "password") 
      .method(Method.POST) 
      .followRedirects(true); 
for (final Entry<String, String> cookie : cookies.entrySet()) { 
    connection.cookie(cookie.getKey(), cookie.getValue()); 
} 
final Response postResponse = connection.execute(); // consume response 
System.out.println(postResponse.body()); 

レスポンスJSON:

{"error":"Invalid username or password."} 

あなたの過ち:

  1. フォームアクションは、クエリ文字列パラメータではありません。したがって.data("action", "/migrate/check")は間違っています。フォームのアクションは、上のコードのようにPOST URLの一部です。

  2. Document document = connection.get();がURLでGETリクエストを行っています。これは間違っています。 connection.execute()は既にPOSTを行っています。ちょうどその応答、final Response postResponse = connection.execute()を読んでください。

  3. 隠された入力を解析する必要はありません。真正性はそのようにします。 Jsoupは私が実証したようにあなたのためにそれを行うことができます。

+0

ありがとうございましたが、もう1つ問題があります。その問題は、Webブラウザがhttps://account.mojang.com/migrate/chooseEmailにリンクして、404エラーを返すことです。ウェブブラウザがどのようにそこに着くのかわからない、それはアカウントを移行する選択肢があるページです –

関連する問題