简体   繁体   English

使用Jsoup登录到pastebin

[英]Logging in to pastebin using Jsoup

I'm trying to connect to pastebin and login. 我正在尝试连接到pastebin并登录。 When i run this, the HTML doesn't show that I have logged in and my profile ID isn't anywhere in the script. 运行此命令时,HTML不会显示我已登录,并且我的个人资料ID不在脚本中的任何位置。

    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. 我相信所有数据字段都是正确的,php显示正在使用POST方法,应该没问题。 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 结束

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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