|
关于HttpHelper获取用户权限后再次执行GET 方法(含COOKIE)报500错误或者查询不到结果
1、用POST 进行模拟登陆 登陆成功后取COOKIE
HttpHelper http = new HttpHelper();
//创建Httphelper参数对象
HttpItem item = new HttpItem()
{
URL =URL_BASE + SecurityCheck1,//URL 必需项
Method = "POST",//URL 可选项 默认为Get
ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
Postdata = SecurityCheckParam,
Encoding=Encoding.UTF8,
Allowautoredirect = false,
ResultCookieType = ResultCookieType.CookieCollection
};
//请求的返回值对象
HttpResult result = http.GetHtml(item);
//获取请求的Cookie
//new CookieCollection();
//if(.Count>1)
//cookie.Add(result.CookieCollection[1]);
////
CookieCollection cookie = result.CookieCollection;
//List<string> list = new List<string>();
//list.Add(result.Header.Get("Set-Cookis") ;
string strcookies=result.Header.Get("Set-Cookie");//.IndexOf("JSE")
strcookies=strcookies.Substring(strcookies.IndexOf("JSE"));
////
// 第二次使用Cookie
//创建Httphelper参数对象
item = new HttpItem()
{
URL = URL_BASE + SecurityCheck,//URL 必需项
Method = "get",//URL 可选项 默认为Get
ContentType = "application/Json",//返回类型 可选项有默认值
//CookieCollection = cookie,//把Cookie写入请求串中
//CookieCollection = result.CookieCollection,
Allowautoredirect=false,
Encoding = Encoding.UTF8,
AcceptEncoding = "gzip, deflate",
Accept="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
ResultCookieType = ResultCookieType.CookieCollection
};
//iAccept-Encoding: gzip, deflate
//item.a
item.KeepAlive = true;
//item.Cookie = "JSESSIONID=3C7EEAFB3B95109128CAB171C695781B";
//item.CookieCollection =new CookieCollection ();
item.Cookie = strcookies;
//item.Cookie = cookie.ToString();
//请求的返回值对象
result = http.GetHtml(item);
//获取Html
string html = result.Html;
MessageBox.Show(html.ToString());
}
|
|