繁体   English   中英

尝试使用Jsoup登录到站点,但无济于事

[英]Trying to Log In to a site using Jsoup and nothing works

我一直在尝试使用Jsoup登录到站点,并且一直在尝试这里每个线程上的所有建议,但似乎没有任何效果。

public static void main(String[] args) throws Exception {

   Connection.Response loginForm = Jsoup.connect("http://webspace.apiit.lk/index.jsp")
        .method(Connection.Method.GET)
        .execute();

Response res = Jsoup.connect("http://webspace.apiit.lk/index.jsp")
        .data("UserID", "cb004277")
        .data("Password", " ")
        //.data("Submit", "Log In")
        .cookies(loginForm.cookies())
        .method(Method.POST)
        .execute();

Map<String, String> cookies = res.cookies();

   Document doc = Jsoup.connect("http://webspace.apiit.lk/index.jsp").cookies(cookies).get();

System.out.println(doc);

有人可以看看让我知道我做错了吗?

来自Java文档

暂停

连接超时(int millis)设置请求超时(连接和读取)。 如果发生超时,将抛出IOException。 默认超时为3秒(3000毫秒)。 零超时被视为无限超时。 参数:millis-超时连接或读取之前的毫秒数(千分之一秒)。 返回:此连接,用于链接

我试图访问该页面,但加载时间确实太长。 尝试这个

public static void main(String[] args) throws Exception {

   Connection.Response loginForm = Jsoup.connect("http://webspace.apiit.lk/index.jsp")
        .timeout(0)  //0 means infinite
        .method(Connection.Method.GET)
        .execute();

   Response res = Jsoup.connect("http://webspace.apiit.lk/index.jsp")
        .timeout(0)  //0 means infinite
        .data("UserID", "cb004277")
        .data("Password", " ")
        //.data("Submit", "Log In")
        .cookies(loginForm.cookies())
        .method(Method.POST)
        .execute();

   Map<String, String> cookies = res.cookies();

   Document doc = Jsoup.connect("http://webspace.apiit.lk/index.jsp").cookies(cookies).get();

   System.out.println(doc);
}

暂无
暂无

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

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