下面列出两个类的实现方法,可以实现提交,但要指出的是,这两个方法都没有实现COOKIES的传递,所以只能提交,但是并不能保存cookies记录。下一次发布的时候将来发布日前写的一个小软件AutoClick,它是一个能自实现自动登录,并发布数据的功能,如果再加上一个蜘蛛那就是一个自已灌水机了,呵呵。
WebClient方法:
System.Net.WebClient wc = new WebClient();
wc.Headers.Add("Accept-Language", "zh-cn");
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string cont = System.Web.HttpUtility.UrlEncode(content, System.Text.Encoding.Default);
string postData = string.Format("username=xxx&password=xxx&to={0}&content={1}", tel,cont);
byte[] bReturn = wc.UploadData("http://xxx.com/xx.asp?", "POST", System.Text.Encoding.Default.GetBytes(postData));
wc.Dispose();
return System.Text.Encoding.GetEncoding("gb2312").GetString(bReturn);
wc.Headers.Add("Accept-Language", "zh-cn");
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string cont = System.Web.HttpUtility.UrlEncode(content, System.Text.Encoding.Default);
string postData = string.Format("username=xxx&password=xxx&to={0}&content={1}", tel,cont);
byte[] bReturn = wc.UploadData("http://xxx.com/xx.asp?", "POST", System.Text.Encoding.Default.GetBytes(postData));
wc.Dispose();
return System.Text.Encoding.GetEncoding("gb2312").GetString(bReturn);
HttpWebRequest方法:
private void Page_Load(object sender, System.EventArgs e)
res;
}
关于协议冲突:在ASP.NET 2.0里使用web.config设置:
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing = "true"/>
</settings>
</system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing = "true"/>
</settings>
</system.net>