Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>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&lt;String, String&gt; 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&lt;String, String&gt; cookie : cookies.entrySet()) { connection.cookie(cookie.getKey(), cookie.getValue()); } final Response postResponse = connection.execute(); // consume response System.out.println(postResponse.body()); </code></pre> <p>Response JSON:</p> <pre><code>{"error":"Invalid username or password."} </code></pre> <p>Your Mistakes:</p> <ol> <li><p>The form action is not a query string parameter. Thus <code>.data("action", "/migrate/check")</code> is incorrect. The form action is part of the POST URL as shown in my code above.</p></li> <li><p><code>Document document = connection.get();</code> is making a GET request at the URL. This is incorrect. <code>connection.execute()</code> has already made a POST. Just read the response, <code>final Response postResponse = connection.execute()</code>. </p></li> <li><p>There's no need to parse the hidden input, authenticityToken like that. Jsoup can do it for you as I have demonstrated. </p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload