博园不知道有高手能用httpwebrequest模拟登录北方网,网址:https://secure.enorth.cn/user/login
我研究了很久都未能成功,所以请高手帮忙,如有能解决的,高分相送,感激不尽!
你看一下他的http头如下:
https://secure.enorth.cn/user/login;jsessionid=D41573233B235D660E59BDE2F38ACA56
POST /user/login;jsessionid=D41573233B235D660E59BDE2F38ACA56 HTTP/1.1
Host: secure.enorth.cn
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; zh-CN; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 (.NET CLR 4.0.20506)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: https://secure.enorth.cn/user/login
Cookie: JSESSIONID=D41573233B235D660E59BDE2F38ACA56
Content-Type: application/x-www-form-urlencoded
Content-Length: 218
username=username&password=22222&rememberMe=true<=_cBC494B2F-BB64-00D1-EFD6-7B72A32AB182_k94CF2E81-65F0-979D-B3F1-EEA2E57FB111&_eventId=submit&submit_chgByZs.x=36&submit_chgByZs.y=18&submit_chgByZs=%E7%99%BB%E5%BD%95
请求头照着写应该就没有问题了
然后呢得到set-cookie如下代码
HttpWebResponse rep = (HttpWebResponse)web.GetResponse();
// 从响应头中获取验证的cookie信息
string setck = rep.Headers["Set-Cookie"];
if (setck!=null&&setck.Trim() != "")
{
string[] cks = setck.Split(new string[] { ";", "/," }, StringSplitOptions.RemoveEmptyEntries);
foreach (string ck in cks)
{
int aa = ck.IndexOf("=");
string name = ck.Substring(0, aa).Trim();
string cValue = ck.Substring(aa + 1).Trim();
if (name.ToLower() != "expires" && name.ToLower() != "path")
{
MyCookie[] my = LiCookie.ToArray();
for (int i = 0; i < my.Length; i++)
{
if (my[i].name == name)
{
LiCookie.Remove(my[i]);
}
}
LiCookie.Add(new MyCookie(name, cValue));
}
}
没时间跟你写了,这样做没错的,可可
部分可以参考:http://www.cnblogs.com/lulu/archive/2009/11/07/1597971.html