导航

  • 首页
  • My230博客
  • 管理知识
  • seo知识
  • 服务器知识
  • java知识
  • asp.net知识
  • asp知识
  • sql知识
  • 网页知识
  • css知识
  • js知识
  • 电脑知识
« C# webservice的简单示例实现IEnumerable 和 IEnumerator, 使类型具备枚举功能的注意 »

C#.net模拟提交表单POST





方法一、
System.Net.WebClient WebClientObj = new System.Net.WebClient();
System.Collections.Specialized.NameValueCollection PostVars = new System.Collections.Specialized.NameValueCollection();
PostVars.Add("A1","0");
PostVars.Add("A2","0");
PostVars.Add("A3","000");
try
{
byte[] byRemoteInfo = WebClientObj.UploadValues("http://www.lovezhao.com/vote.asp","POST",PostVars);
//下面都没用啦,就上面一句话就可以了
string sRemoteInfo = System.Text.Encoding.Default.GetString(byRemoteInfo);
//这是获取返回信息
richTextBox_instr.Text += sRemoteInfo;
}
catch
{}

方法二、
string url = "网址";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
string s = "要提交的数据";
byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes (LoginInfo);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = requestBytes.Length;
Stream requestStream = req.GetRequestStream();
requestStream.Write(requestBytes,0,requestBytes.Length);
requestStream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
string backstr = sr.ReadToEnd(); Response.Write(line); sr.Close(); res.Close();

  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表




Copyright 2010-2013 上网首页