我用的是httpclient4.3.6 。我模拟登陆我们学校的网站,获取了cookies,但是我用httpwatch看 有重定向的问题,我不知道怎么进入后面的网页!求解!我贴上代码,求代码详解,谢谢!!!小弟初学java 现需要做这个操作,很是艰难呀!感激不尽!
4条回答
- Void_main_For_you 2014-12-02 04:36关注
public class Test {
public static void main(String[] args) throws Exception { BasicCookieStore cookieStore = new BasicCookieStore(); CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCookieStore(cookieStore) .build(); try { HttpUriRequest login = RequestBuilder.post() .setUri(new URI("http://portal.sicnu.edu.cn:82/cas/login")) .addParameter("action","DCPLogin") .addParameter("encodedService","http%3a%2f%2fportal.sicnu.edu.cn%2fcas.jsp") .addParameter("lt","LT_M5000-R_-592543-IhH4ao22pYE5PM83cHXa") .addParameter("password", "123456") .addParameter("service","http://portal.sicnu.edu.cn/cas.jsp") .addParameter("serviceName","null") .addParameter("username", "2013110401") .build(); String MainURL = "http://portal.sicnu.edu.cn/portal/media-type/html/role/school/page/default.psml/js_pane/P-132fb077a30-1000d"; CloseableHttpResponse response2 = httpclient.execute(login); try { HttpEntity entity = response2.getEntity(); System.out.println("Login form get: " + response2.getStatusLine()); EntityUtils.consume(entity); System.out.println("Post logon cookies:"); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } }finally{ response2.close(); } }finally{ httpclient.close(); }
解决 无用评论 打赏 举报
悬赏问题
- ¥15 c程序不知道为什么得不到结果
- ¥40 复杂的限制性的商函数处理
- ¥15 程序不包含适用于入口点的静态Main方法
- ¥15 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置