Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final String USER_AGENT = ""Mozilla/5.0 (Windows NT" +n" +
- "" 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.120 Safari/535.2"";
- String loginFormUrl = "https://page.com/login";
- String loginActionUrl = "https://page.com/json";
- String username = "email@gmail.com";
- String password = "XXXX";
- HashMap<String, String> cookies = new HashMap<>();
- HashMap<String, String> formData = new HashMap<>();
- Connection.Response loginForm = Jsoup.connect(loginFormUrl).method(Connection.Method.GET).userAgent(USER_AGENT).execute();
- Document loginDoc = loginForm.parse(); // this is the document that contains response
- cookies.putAll(loginForm.cookies()); // save the cookies, this will be passed on to next request
- formData.put("commit", "Sign in");
- formData.put("utf8", "e2 9c 93");
- formData.put("login", username);
- formData.put("password", password);
- formData.put("authenticity_token", authToken);
- Connection.Response homePage = Jsoup.connect(loginActionUrl)
- .cookies(cookies)
- .data(formData)
- .method(Connection.Method.POST)
- .userAgent(USER_AGENT)
- .execute();
- System.out.println(homePage.parse().html()); //The json response use this to iterate and draw
Add Comment
Please, Sign In to add comment