From c86b02709e0ff1ec0d55a75146a03a09f89863ad Mon Sep 17 00:00:00 2001 From: Arronlong Date: Thu, 7 Jan 2016 14:20:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9demo=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E8=AE=BE=E7=BD=AEuseragent=EF=BC=8C=E5=80=BC=E4=B8=AD=E5=8E=BB?= =?UTF-8?q?=E6=8E=89useragent=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/tgb/ccl/http/TestCookie.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/tgb/ccl/http/TestCookie.java b/src/test/java/com/tgb/ccl/http/TestCookie.java index bb2ac27..09f109e 100644 --- a/src/test/java/com/tgb/ccl/http/TestCookie.java +++ b/src/test/java/com/tgb/ccl/http/TestCookie.java @@ -31,12 +31,14 @@ public static void main(String[] args) throws HttpProcessException { //C币查询 String scoreUrl = "http://my.csdn.net/my/score"; + //定义cookie存储 HttpClientContext context = new HttpClientContext(); CookieStore cookieStore = new BasicCookieStore(); context.setCookieStore(cookieStore); + //获取参数 String loginform = HttpClientUtil.send(loginUrl, context); -// System.out.println(loginform); + //System.out.println(loginform); System.out.println("获取登录所需参数"); String lt = regex("\"lt\" value=\"([^\"]*)\"", loginform)[0]; String execution = regex("\"execution\" value=\"([^\"]*)\"", loginform)[0]; @@ -52,7 +54,7 @@ public static void main(String[] args) throws HttpProcessException { //发送登录请求 String result = HttpClientUtil.send(loginUrl, map, context); -// System.out.println(result); + //System.out.println(result); if(result.contains("帐号登录")){//如果有帐号登录,则说明未登录成功 String errmsg = regex("\"error-message\">([^<]*)<", result)[0]; System.err.println("登录失败:"+errmsg);