我正在尝试使用JSoup post方法登录网站.我看到了一些例子,但都没有对我有用.
我正在尝试登录: http://ug.technion.ac.il/Tadpis.html
为此,我有以下代码:
我正在尝试登录: 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参数,但请自行检查.