Guest User

Untitled

a guest
Oct 2nd, 2018
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. final String USER_AGENT = ""Mozilla/5.0 (Windows NT" +n" +
  2. "" 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.120 Safari/535.2"";
  3. String loginFormUrl = "https://page.com/login";
  4. String loginActionUrl = "https://page.com/json";
  5. String username = "email@gmail.com";
  6. String password = "XXXX";
  7.  
  8. HashMap<String, String> cookies = new HashMap<>();
  9. HashMap<String, String> formData = new HashMap<>();
  10.  
  11.  
  12. Connection.Response loginForm = Jsoup.connect(loginFormUrl).method(Connection.Method.GET).userAgent(USER_AGENT).execute();
  13. Document loginDoc = loginForm.parse(); // this is the document that contains response
  14.  
  15. cookies.putAll(loginForm.cookies()); // save the cookies, this will be passed on to next request
  16.  
  17. formData.put("commit", "Sign in");
  18. formData.put("utf8", "e2 9c 93");
  19. formData.put("login", username);
  20. formData.put("password", password);
  21. formData.put("authenticity_token", authToken);
  22.  
  23. Connection.Response homePage = Jsoup.connect(loginActionUrl)
  24. .cookies(cookies)
  25. .data(formData)
  26. .method(Connection.Method.POST)
  27. .userAgent(USER_AGENT)
  28. .execute();
  29.  
  30. System.out.println(homePage.parse().html()); //The json response use this to iterate and draw
Add Comment
Please, Sign In to add comment