求助,java爬虫Cookie问题

代码如下(账号密码部分替换了):

    public void login(){
        String url = "http://www.ekgc.cn/member/elogin?redirect_url=http://www.ekgc.cn";
        String data = "KgcForm_models_LoginForm%5Bidentity%5D=账号&KgcForm_models_LoginForm%5Bpassword%5D=md5加密后的密码";
        try {
            NetUtil netUtil = new NetUtil();
            Connection con = Jsoup.connect(url);

            con.method(Connection.Method.POST);
            con.header("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
            con.header("Host","www.ekgc.cn");
            con.header("Referer","http://www.ekgc.cn/member/elogin?redirect_url=http://www.ekgc.cn");
            con.header("User-Agent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36");
            con.followRedirects(false);
            con.data(data);

            Connection.Response res = con.execute();
            Map map = res.headers();
            for(Map.Entry entry : map.entrySet()) {
                System.out.println(entry.getKey() + "=" + entry.getValue());
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

如图,登录成功返回头如下:

求助,java爬虫Cookie问题_第1张图片

 密码错误,返回的头信息如下:求助,java爬虫Cookie问题_第2张图片

下图是模拟登录返回的头:求助,java爬虫Cookie问题_第3张图片  

你可能感兴趣的:(问题大全)