我想爲minecraft.net製作一個用戶名migrater作爲mod,這樣人們將能夠遷移他們的帳戶遊戲以阻止帳戶的破解。爲了做到這一點,我需要將表單發佈到網站上。我設法成功獲取cookie,以便authenticityToken保持不變,但每當我嘗試將數據發回網站時,都會拋出'java.io.IOException:嘗試加載URL時發生太多重定向https://account.mojang.com/migrate'JSoup引發IO異常:嘗試加載URL時出現太多重定向
我真的不知道爲什麼會發生這種情況,但可能與網站有關。 authenticityToken絕對匹配。我沒有發佈到網站並提供相同的cookie,我檢查了這一點。這是我目前使用的
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();
}
任何幫助都將不勝感激代碼大大
奇怪的是,我沒有遇到任何重定向循環。他的要求是不正確的,但是對我來說這只是一個404。 –