|
ContentType的默认值为:text/html, application/xhtml+xml, */*这样我登录不成功,但是改为 application/x-www-form-urlencoded就可以了,为什么?ContentType我不设定也登入不了?我如何知道要设定ContentType为何值呢?
private void btn2_Click(object sender, EventArgs e)
{
string formhash = "";
THttpHelper http = new THttpHelper();
HttpItem item = new HttpItem()
{
URL = "http://www.sufeinet.com/member.php?mod=logging&action=login",//URL 必需项
Encoding = System.Text.Encoding.GetEncoding("gbk"),//URL 可选项 默认为Get
Method = "get",//URL 可选项 默认为Get
Cookie = "",//字符串Cookie 可选项
UserAgent = "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统 可选项有默认值
ContentType = "text/html",//返回类型 可选项有默认值
};
HttpResult result = http.GetHtml(item);
string cookie = result.Cookie;
//提取formhash
formhash = Regex.Match(result.Html, @"(?<=formhash=)\w+").Value;
item = new HttpItem()
{
URL = "http://www.sufeinet.com/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=Ld7k8&inajax=1",//URL 必需项
Encoding = System.Text.Encoding.GetEncoding("gbk"),//URL 可选项 默认为Get
Method = "post",//URL 可选项 默认为Get
Cookie = result.Cookie,//字符串Cookie 直接用第一次GET到的cookie
Referer = "http://www.sufeinet.com/member.php?mod=logging&action=login",//来源URL 可选项
Postdata = "formhash=" + formhash + "&referer=http%3A%2F%2Fwww.sufeinet.com%2F.%2F&loginfield=username&username=" + txt1.Text + "&password=" + txt2.Text + "&questionid=0&answer=",//Post数据
Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
UserAgent = "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统 可选项有默认值
ContentType = "text/html",//问题在于这一句 application/x-www-form-urlencoded
};
result = http.GetHtml(item);
string html = result.Html;
cookie = result.Cookie;
rtxt1.Text = html;
} |
|