且构网

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

使用 JSoup post 方法登录网站

更新时间:2023-12-03 21:31:10

您在地址栏中看到的 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();

附言我相信 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.