浏览器上网页登陆正常跳转,用httphelper跳转返回数据长度为0,对比了浏览器提交的数据和用httphelper提交的数据是一模一样的,求各位大神提供思路
[C#] 纯文本查看 复制代码 public static string login(string name ,string pwd)
{
HttpHelper http = new HttpHelper();
System.Net.WebHeaderCollection header = new System.Net.WebHeaderCollection();
//header.Add("Accept-Encoding: gzip, deflate");
HttpItem item = new HttpItem()
{
URL = "http://www.gxpx365.com/jsp/portal/logining1.jsp",//登陆地址
Method = "post",//URL 可选项 默认为Get
Referer = "http://www.gxpx365.com/jsp/portal/index.jsp",//
ContentType = "application/x-www-form-urlencoded",
Postdata = String.Format("name={0}&pwd={1}&role=student",name,pwd),
KeepAlive = true,
Header = header,
// AutoRedirectCookie = true,
// Allowautoredirect = true,
};
//得到HTML代码
//item.Allowautoredirect = true;
HttpResult result = http.GetHtml(item);
// string html = result.Html;
bool loginrs = result.Cookie.Contains("USER=");
string userid = HttpCookieHelper.GetCookieValue("USER", result.Cookie);
string jid = HttpCookieHelper.GetCookieValue("JSESSIONID",result.Cookie);
header.Add("Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3");
if (loginrs)
{
item.URL = "http://www.gxpx365.com/jsp/portal/../../cmd/navigatorcontrol?flag=menu";
item.Method = "get";
//item.ContentType = "text/html";
item.Cookie = string.Format("JSESSIONID={0};USER={1}",jid , userid);
item.Referer = "http://www.gxpx365.com/jsp/portal/index.jsp";
item.Header = header;
item.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, */*";
HttpResult result2 =http.GetHtml(item);
//getUser(result.Cookie);
return result.Cookie;
}
return null;
}
|