用一般的HttpWebRequest请求是正常的
代码如下:
[C#] 纯文本查看 复制代码 var cookies = new CookieContainer();
var request = (HttpWebRequest)WebRequest.Create("http://www.maxbet.com/Default.aspx");
request.Referer = "http://www.maxbet.com/";
request.ServicePoint.Expect100Continue = false;
request.CookieContainer = cookies;
request.GetResponse().Close();
var langRequest = (HttpWebRequest)WebRequest.Create("http://www.maxbet.com/ChangeLanguage.aspx");
langRequest.Method = "POST";
langRequest.CookieContainer = cookies;
langRequest.ContentType = "application/x-www-form-urlencoded";
langRequest.Referer = "http://www.maxbet.com/topmenu.aspx";
langRequest.AllowAutoRedirect = false;
var postdata = Encoding.Default.GetBytes("hidIsLogin=yes&hidSelLang=cs");
langRequest.ContentLength = postdata.Length;
using (var stream = langRequest.GetRequestStream())
{
stream.Write(postdata, 0, postdata.Length);
}
Console.WriteLine(new StreamReader(((HttpWebResponse)langRequest.GetResponse()).GetResponseStream()).ReadToEnd());
Console.ReadLine();
打印出:
[C#] 纯文本查看 复制代码 <script> top.window.location.href='./main.aspx?'</script>
换成HttpHelper请求
代码如下:
[C#] 纯文本查看 复制代码 var item = new HttpItem
{
URL = "http://www.maxbet.com/Default.aspx",
Referer = "http://www.maxbet.com/",
Expect100Continue = false
};
var result = (new HttpHelper()).GetHtml(item);
var langItem = new HttpItem
{
URL = "http://www.maxbet.com/ChangeLanguage.aspx",
Method = "POST",
Postdata = "hidIsLogin=yes&hidSelLang=cs",
Cookie = result.Cookie,
ContentType = "application/x-www-form-urlencoded",
Referer = "http://www.maxbet.com/topmenu.aspx",
Allowautoredirect = false,
};
var langResult = (new HttpHelper()).GetHtml(langItem);
Console.WriteLine(langResult.Html);
Console.ReadLine();
反而出现了下面的错误讯息:
[C#] 纯文本查看 复制代码 The connection was closed unexpectedly
求救!
|