java版chsi.com.cn模拟登陆

原创
2019/02/14 09:10
阅读数 602

直接上代码登陆chsi.com.cn测试:


		// TODO Auto-generated method stub
		String url = "https://account.chsi.com.cn/passport/login?service=https://my.chsi.com.cn/archive/j_spring_cas_security_check";
		String userAgent = "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36";
        RequestConfig requestConfig = RequestConfig.custom()
                .setConnectTimeout(5000*10)   //设置连接超时时间
                .setConnectionRequestTimeout(5000*10) // 设置请求超时时间
                .setSocketTimeout(5000*10)
                .setRedirectsEnabled(true)//默认允许自动重定向
                .build();
        CloseableHttpClient httpCilent = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet(url);
        httpGet.setHeader("User-Agent",userAgent);
        httpGet.setConfig(requestConfig);
        HttpResponse httpResponse = httpCilent.execute(httpGet);
        HttpEntity entity = httpResponse.getEntity();
        String contentString = EntityUtils.toString(entity,"utf-8");
        Document document = Jsoup.parse(contentString);
        Elements eles = document.select("input[type=hidden]");
        List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();
        for (Element element : eles) {
			String nameString = element.attr("name");
			String valueString = element.attr("value");
			list.add(new BasicNameValuePair(nameString, valueString));
		}
        
        list.add(new BasicNameValuePair("username", "你的用户名"));
        list.add(new BasicNameValuePair("password", "你的密码"));
        
        HttpPost post = new HttpPost(url);
        post.setHeader("User-Agent",userAgent);
        post.setHeader("Referer","https://account.chsi.com.cn/passport/login?service=https://my.chsi.com.cn/archive/j_spring_cas_security_check");
        HttpEntity ent = new UrlEncodedFormEntity(list, "UTF-8");
        post.setEntity(ent);
        httpResponse = httpCilent.execute(post);
        
        
       // httpGet = new HttpGet("https://my.chsi.com.cn/archive/gdjy/xj/show.action");
        httpGet = new HttpGet("https://account.chsi.com.cn/account/account!show");
        httpGet.setHeader("User-Agent",userAgent);
        httpGet.setConfig(requestConfig);
        httpResponse = httpCilent.execute(httpGet);
        entity = httpResponse.getEntity();
        contentString = EntityUtils.toString(entity,"utf-8");
        System.out.println("======================-----下面就是登陆后的东西 请拷贝查看-----=================");
        System.out.println(contentString);
	

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部