[C#] 纯文本查看 复制代码 string data = "loginUserName=" + zh + "&loginUserPsd=" + pwd;
string url = "http://hy.3yx.com/login_submit";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.Host = "hy.3yx.com";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3");
request.Headers.Add("Accept-Encoding", "gzip, deflate");
request.Referer = "http://hy.3yx.com/login?s_from=6A7FFE81F3094D48EB40CF95FF82516578540F4A5BD7BC84";
request.CookieContainer = cc;
request.ContentType = "application/x-www-form-urlencoded";
//request.ServicePoint.Expect100Continue = true;
request.AllowAutoRedirect = true;
request.MaximumAutomaticRedirections = 1;
string newUrl = request.Headers["Location"];//获取重定向的网址
// request.KeepAlive = true;
request.ContentLength = System.Text.Encoding.UTF8.GetBytes(data).Length;
request.Timeout = 20000;
System.IO.Stream smWrite = request.GetRequestStream();
smWrite.Write(System.Text.Encoding.UTF8.GetBytes(data), 0, System.Text.Encoding.UTF8.GetBytes(data).Length);
smWrite.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
WebHeaderCollection Headers = response.Headers;
//Stream myResponseStream = new System.IO.Compression.GZipStream(response.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("GBK"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
//retString = DlbZy("http://www.3yx.com", ref cc);
return retString;
提交可以成功返回[HTML] 纯文本查看 复制代码 <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xHTML1/DTD/xHTML1-transitional.dtd">
<HTML xmlns="http://www.w3.org/1999/xHTML">
<head>
<title>正在跳转...</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
</head>
<body>
<script type="text/javascript">
<!--
function go_to_url(){
window.location.href="http://www.3yx.com:80";
}
go_to_url();
//-->
</script>
</body>
</html> |