[C#] 纯文本查看 复制代码 CookieContainer _cCookies = new CookieContainer();
_cCookies.Add(cookies);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url.ToString());
myRequest.ProtocolVersion = HttpVersion.Version11;
myRequest.AllowAutoRedirect = false;
myRequest.ServicePoint.Expect100Continue = false;
myRequest.KeepAlive = true;
myRequest.Method = "POST";
myRequest.Timeout = 30000;
SetHeaderValue(myRequest.Headers, "x-requested-with", "XMLHttpRequest");
SetHeaderValue(myRequest.Headers, "Accept-Language", "zh-cn");
if (referer != "")
myRequest.Referer = referer;
myRequest.Accept = "*/*";
myRequest.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
SetHeaderValue(myRequest.Headers, "Accept-Encoding", "gzip, deflate");
myRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)";
SetHeaderValue(myRequest.Headers, "Host", "");
SetHeaderValue(myRequest.Headers, "Content-Length", _iDataLength.ToString());
myRequest.Headers["DNT"] = "1";
SetHeaderValue(myRequest.Headers, "Connection", "Keep-Alive");
SetHeaderValue(myRequest.Headers, "Cache-control", "no-cache");
myRequest.CookieContainer = _cCookies;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(postData, 0, postData.Length);
newStream.Close();
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
Stream streamReceive = myResponse.GetResponseStream();
if (myResponse.ContentEncoding.ToLower() == "gzip")
{
streamReceive = new GZipStream(streamReceive, CompressionMode.Decompress);
}
Encoding encoding = Encoding.GetEncoding(encodingFormat);
StreamReader reader = new StreamReader(streamReceive, encoding);
string outdata = reader.ReadToEnd();
reader.Close();
myResponse.Close();
streamReceive.Close(); |