简体   繁体   中英

Logging in to pastebin using Jsoup

I'm trying to connect to pastebin and login. When i run this, the HTML doesn't show that I have logged in and my profile ID isn't anywhere in the script.

    Response loginResponse;
    Document cur = null;
    Map<String, String> loginCookies;

    loginResponse = Jsoup.connect("http://www.pastebin.com/login.php")
            .data("user_name", name)
            .data("user_password", pwrd)
            .data("submit", "Login")
            .method(Method.POST)
            .execute();



    if (loginResponse != null) 
    {

        loginCookies = loginResponse.cookies();

        try 
        {
            cur = Jsoup.connect("http://www.pastebin.com")
                    .cookies(loginCookies).get();

        } catch (Exception e) {
            e.printStackTrace();
        }

        for (Map.Entry<String, String> entry : loginCookies.entrySet())
        {
            System.out.println(entry.getKey() + "/" + entry.getValue());
        }

        String s = cur.body().html();
        System.out.println(cur.body().html());
        System.out.println(cur.body().html().contains("Arhowk"));

    }

I believe that all the data fields are correct, the php shows the POST method being used, should be fine. I'm fairly new to this and I see alot of pages with answers but I don't see any solutions to this isuse.

Try do this like a browser ;)

  1. open the page:

     loginResponse = Jsoup.connect("http://www.pastebin.com/login.php") .method(Connection.Method.GET) .execute(); 
  2. login

     loginResponse = Jsoup.connect("http://www.pastebin.com/login.php") .data("submit_hidden", "submit_hidden") .data("user_name", name) .data("user_password", pwrd) .data("submit", "Login") .cookies(loginResponse.cookies()) // pass cookies .method(Method.POST) .execute(); 
  3. end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM