栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

通过Jsoup发布方法登录网站不起作用

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

通过Jsoup发布方法登录网站不起作用

您必须分两个阶段登录该站点。
第1阶段-您

GET
向该URL 发送请求-
https://parents.mtsd.k12.nj.us/genesis/parents?gohome=true
并获得
sessioncookies

第2阶段-
您发送
post
带有用户名和密码的请求,然后添加
cookies
您进入第1阶段的请求。
该代码为-


Connection.Response res = null;document doc = null;try {   //first connection with GET request        res = Jsoup.connect("https://parents.mtsd.k12.nj.us/genesis/parents?gohome=true")//       .userAgent(YourUserAgent)//       .header("Accept", WhateverTheSiteSends)//       .timeout(Utilities.timeout)         .method(Method.GET)         .execute();  } catch (Exception ex) {        //Do some exception handling here    }try {        doc = Jsoup.connect("https://parents.mtsd.k12.nj.us/genesis/parents/j_security_check"")    //          .userAgent(YourUserAgent)    //          .referrer(Referer)    //          .header("Content-Type", ...)     .cookies(res.cookies())     .data("j_username",username)     .data("j_password",password)   .post();    } catch (Exception ex) {        //Do some exception handling here    }    //Now you can use doc!

您可能需要添加不同的两个请求

HEADERS
,例如
userAgent
referrer
content-type
等等。在第二个请求结束时,
doc
应具有
HTML
该站点的。

您无法登录该站点的原因是您发送的

post
请求中没有
session cookies
,因此这是来自服务器的无效请求。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/515292.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号