|
楼主 |
发表于 2013-8-22 15:38:10
|
显示全部楼层
本帖最后由 天山明月 于 2013-8-22 15:40 编辑
现在的情况是cookies丢失问题,从日志看cookies2、cookies3都没有信息。
重新整理了下:
httpwatch抓包情况:
Send:
GET /jms/login.jsp HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-powerpoint, application/msword, application/vnd.ms-excel, */*
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.3; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Host: x.x.x.x:8080
Connection: Keep-Alive
Receive:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=1DD543CD1D5B1826EE0EF55183A00353; Path=/jms/; HttpOnly
Cache-Control: no-store
Expires: Wed, 31 Dec 1969 23:59:59 GMT
Pragma: no-cache
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 22 Aug 2013 04:07:59 GMT
2000
<html>
<head>
<meta charset="utf-8"/>
<title>Job Management System</title>
<!-- <link rel="shortcut icon" href="/jms/common/image/favicon.ico" type="image/x-icon" /> -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
<link rel="stylesheet" type="text/css" href="ext4.0/resources/css/ext-all.css" />
<link rel="stylesheet" href="/jms/common/css/login.css" />
<script type="text/javascript" src="/jms/common/js/common.js"></script>
<script type="text/javascript" src="/jms/ext4.0/ext-all.js"></script>
Send:
GET /jms/freshcode.do HTTP/1.1
Accept: */*
Referer: http://x.x.x.x:8080/jms/login.jsp
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.3; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Host: x.x.x.x:8080
Connection: Keep-Alive
Cookie: JSESSIONID=1DD543CD1D5B1826EE0EF55183A00353
Receive:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: image/jpeg;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 22 Aug 2013 04:12:31 GMT
login:
Send:
POST /jms/login.do HTTP/1.1
Accept: */*
Accept-Language: zh-cn
Referer: http://x.x.x.x:8080/jms/login.jsp
x-requested-with: XMLHttpRequest
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.3; .NET4.0C; .NET4.0E)
Host: x.x.x.x:8080
Content-Length: 57
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=1DD543CD1D5B1826EE0EF55183A00353
username=test&password=test&isAutoLogin=0&code=6gsx
Receive:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=UTF-8
Content-Length: 4
Date: Thu, 22 Aug 2013 04:16:28 GMT
True
代码:
[code=csharp] string loginUrl = "http://x.x.x.x:8080/jms/login.jsp";
string freshcodeUrl = "http://x.x.x.x:8080/jms/freshcode.do";
string postUrl = "http://x.x.x.x:8080/jms/login.do";
string dataActionUrl = "http://x.x.x.x:8080/jms/job/jobsteplist.do";
HttpHelper hh = new HttpHelper();
bool loginFail = true;
string verifyCode;
while (loginFail)
{
HttpItem hi = new HttpItem()
{
URL = loginUrl,
Method = "get",//可选项 默认为Get
Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
//Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
//IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
Cookie = "",//字符串Cookie 可选项
UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.3; .NET4.0C; .NET4.0E",//用户的浏览器类型,版本,操作系统 可选项有默认值
Accept = "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-powerpoint, application/msword, application/vnd.ms-excel, */*",// 可选项有默认值
ContentType = "text/html",//返回类型 可选项有默认值
};
HttpResult hr = hh.GetHtml(hi);
string cookies = hr.Cookie;
logger.InfoFormat("Cookies1:{0}", cookies);
hi = new HttpItem()
{
URL = freshcodeUrl,
Method = "get",
Encoding = Encoding.UTF8,
Cookie = cookies,
UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.3; .NET4.0C; .NET4.0E)",
Accept = "*/*",
ContentType = "image/jpeg",
Referer = "http://x.x.x.x:8080/jms/login.jsp",
ResultType = ResultType.Byte,
};
hr = hh.GetHtml(hi);
//cookies = hr.Cookie;
logger.InfoFormat("Cookies2:{0}", hr.Cookie);
MemoryStream ms = new MemoryStream(hr.ResultByte);
Bitmap bitmap = new Bitmap(ms);
verifyCode = SecurityCodeHelper.GetSecurityCode(bitmap);
logger.InfoFormat(verifyCode);
hi = new HttpItem()
{
URL = postUrl,
Method = "post",
Encoding = Encoding.UTF8,
Cookie = cookies,
UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.3; .NET4.0C; .NET4.0E)",
Accept = "*/*",
ContentType = "application/x-www-form-urlencoded",
Referer = "http://x.x.x.x:8080/jms/login.jsp",
ResultType = ResultType.String,
PostDataType = PostDataType.String,
Allowautoredirect = true,
};
hi.Postdata = string.Format("username=test&password=test&isAutoLogin=0&code={0}", verifyCode);
hr = hh.GetHtml(hi);
cookies = hr.Cookie;//login successfully
logger.InfoFormat("Cookies3:{0}", cookies);
logger.InfoFormat("StatusCode:{0}", hr.StatusCode);
string htmlStr = hr.Html;
logger.InfoFormat(htmlStr);
if (htmlStr.IndexOf("key") > -1)
{
logger.InfoFormat("Login Successfully");
loginFail = false;
}//judge login
}[/code]
|
|