html – 使用JSoup post方法登录网站

前端之家收集整理的这篇文章主要介绍了html – 使用JSoup post方法登录网站前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用JSoup post方法登录网站.我看到了一些例子,但都没有对我有用.
我正在尝试登录http://ug.technion.ac.il/Tadpis.html
为此,我有以下代码
String url = "http://ug.technion.ac.il/Tadpis.html";
 doc = Jsoup.connect(url).data("userid","my_user_id")
                .data("password","my_password").data("function","signon").data("submit","Signon").post();

显然我错过了一些数据(我不知道哪个).另一件我不明白的事情就是网址.检查上面的网址的html我可以看到这一行:

<form action="http://techmvs.technion.ac.il:80/cics/wmn/wmngrad?aapmlkwi&ORD=1&s=1" method="POST" name="SignonForm"

这是与上述不同的网址.我想将哪一个用作“连接”方法的url参数?

谢谢!

解决方法

您在地址栏中看到的网址不是您要向其发出的网址.您应该将请求发送到您在表单中看到的第二个网址.
//With this you login and a session is created
    Connection.Response res = Jsoup.connect("http://techmvs.technion.ac.il:80/cics/wmn/wmngrad?aapmlkwi&ORD=1&s=1")
        .data("username","myUsername","password","myPassword")
        .method(Method.POST)
        .execute();

//This will get you cookies
Map<String,String> loginCookies = res.cookies();

//Here you parse the page that you want. Put the url that you see when you have logged in
Document doc = Jsoup.connect("urlYouNeedToBeLoggedInToAccess")
      .cookies(loginCookies)
      .get();

附:我相信http://techmvs.technion.ac.il:80/cics/wmn/wmngrad就足够了.您不需要额外的GET参数,但请自行检查.

原文链接:https://www.f2er.com/html/232070.html

猜你在找的HTML相关文章