我正在尝试为我的世界制作一些东西,使某人能够登录到他们的 mojang 帐户。我正在尝试用 jsoup 做到这一点。但是有一个问题,当它重定向到https://account.mojang.com/me这是正常的登录页面时,它会引发 404 错误?
public String connect() {
try {
final Response response =
Jsoup.connect("https://account.mojang.com/login").execute();
final Document doc = response.parse();
final Element authToken = doc.select("input[name^=authenticityToken]").get(0);
final Map<String, String> cookies = response.cookies();
final Connection connection =
Jsoup.connect("https://account.mojang.com/login")
.data("authenticityToken", authToken.val())
.data("username", "email")
.data("password", "password")
.method(Method.POST)
.followRedirects(true);
connection.timeout(10000);
for (final Entry<String, String> cookie : cookies.entrySet()) {
connection.cookie(cookie.getKey(), cookie.getValue());
}
final Response postResponse = connection.execute();
return postResponse.body().toLowerCase();
} catch (Exception e) { e.printStackTrace(); return "try again"; }
}
任何帮助将不胜感激