Java Reference
In-Depth Information
// Request Twitter homepage and get token
Connection initialConnection = Jsoup.connect(" https://twitter.com/");
Document initialResult = initialConnection.get();
String authenticityToken = initialResult
.select("input[name=authenticity_token]").get(0).val();
// Update cookies
COOKIES.putAll(initialConnection.response().cookies());
return authenticityToken;
}
}
This code is mostly similar to the one you saw previously, with the difference that you're now mak-
ing POST requests, setting and sending cookies, and using more complex selectors. If you're wonder-
ing how you can figure out the names of the POST parameters to send along with the login request,
these can be obtained by inspecting network traffic using the developer tools in any modern web
browser (e.g., Firefox or Chrome). See Figure 10-30.
figure 10-30  
Search WWH ::




Custom Search