且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用JSoup发布方法登录网站

更新时间:2023-12-03 21:18:34

您在地址栏中看到的网址不是您要向其发出请求的网址.您应该向表单中看到的第二个URL发出请求.

The url that you see in the address bar is not the one that you want to make the request to. You should make the request to the second url that you see in the form.

//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();

P.S.我相信 http://techmvs.technion.ac.il:80/cics/wmn/wmngrad 就足够了.您不需要额外的GET参数,而是自己检查一下.

P.S. I believe that http://techmvs.technion.ac.il:80/cics/wmn/wmngrad is enough. You don't need the extra GET parameters, but check it for yourself.