我正在努力为我的世界制造一些东西,使某人能够登录他们的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"; }
}
非常感谢任何帮助
答案 0 :(得分:0)
您应该使用
使用整个Cookie Map变量.cookies(cookies);
我从未玩过Minecraft,但在我看来,你应该用
打印回复postResponse.parse();
看看是否没有Javascript重定向。由于Jsoup不是为执行Javascript而构建的,因此它不会将您重定向到您想要的位置。还.. ..
.followRedirects(false);
您是否尝试将其设为true,看看会发生什么? (我会尝试打印它获得的页面,看看Jsoup是否重定向)
答案 1 :(得分:0)
网站是否有SSL加密?这可能是一个问题