C#.net模拟提交表单POST
2008-07-18 14:32
519 查看
方法一、
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();
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();
相关文章推荐
- C#.net模拟提交表单GET、POST
- C#模拟提交表单 post-带附件的表单
- 黄聪:C#模拟网站页面POST数据提交表单(一)--WebClient (转)
- C#模拟web请求,使用post提交带有文件的数据表单
- C#模拟POST提交表单(二)--HttpWebRequest以及HttpWebResponse
- C#模拟POST提交表单(一)--WebClient
- C#模拟POST提交表单--WebClient
- 转载 C# Winform利用POST传值方式模拟表单提交数据(Winform与网页交互)
- 黄聪:C#模拟网站页面POST数据提交表单(二)--HttpWebRequest以及HttpWebResponse (转)
- C#模拟POST提交表单
- C#模拟POST提交表单--WebClient
- C# Winform利用POST传值方式模拟表单提交数据(Winform与网页交互)
- C# 模拟post数据提交时 出现如下错误: System.Net.WebException: 远程服务器返回错误: (417) Expectation Failed 的解决办法
- C# Winform利用POST传值方式模拟表单提交数据
- C#模拟POST提交表单--HttpWebResponse
- C# .NET 提交表单POST
- C# .NET 提交表单POST之另一种方法
- C#模拟POST提交表单(一)--WebClient
- C# Winform利用POST传值方式模拟表单提交数据(Winform与网页交互)
- C#模拟POST提交表单--HttpWebRequest以及HttpWebResponse