winform 怎么使用post 或get 向网页传递数据?
1 winform 里怎么用post 或 get 向网页传递数据?
{
CookieContainer cc = new CookieContainer();
string pos tData = "user=" + strUser + "&pass=" + strPsd;
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化
HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(new Uri("http://www.xxxx.com/chk.asp"));
webRequest2.CookieContainer = cc;
webRequest2.Method = "POST";
webRequest2.ContentType = "application/x-www-form-urlencoded";
webRequest2.ContentLength = byteArray.Length;
Stream newStream = webRequest2.GetRequestStream();
// Send the data.
newStream.Write(byteArray, 0, byteArray.Length); //写入参数
newStream.Close();
HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
StreamReader sr2=new StreamReader(response2.GetResponseStream(), Encoding.Default); //每次到这里就报错: 未处理的WebException 操作超时
string text2 = sr2.ReadToEnd();
......
}
这是怎么回事?
2 winform里怎么获取访问一个网页时返回的http请求状态?(比如:http 500 或404等)
private bool PostWebRequest() {
CookieContainer cc = new CookieContainer();
string pos tData = "user=" + strUser + "&pass=" + strPsd;
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化
HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(new Uri("http://www.xxxx.com/chk.asp"));
webRequest2.CookieContainer = cc;
webRequest2.Method = "POST";
webRequest2.ContentType = "application/x-www-form-urlencoded";
webRequest2.ContentLength = byteArray.Length;
Stream newStream = webRequest2.GetRequestStream();
// Send the data.
newStream.Write(byteArray, 0, byteArray.Length); //写入参数
newStream.Close();
HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
StreamReader sr2=new StreamReader(response2.GetResponseStream(), Encoding.Default); //每次到这里就报错: 未处理的WebException 操作超时
string text2 = sr2.ReadToEnd();
......
}
这是怎么回事?
2 winform里怎么获取访问一个网页时返回的http请求状态?(比如:http 500 或404等)
...全文
相关推荐
winform GET请求和POST请求
winform GET请求和POST请求! 很值得下载看看!资源免费,大家分享!!
C# Winform和网页表单交互(提交和获取)
C# Winform和网页表单交互(提交和获取)。 高手参考用,新手学习用,Vs2008写的 C# 网页 提交 获取 表单
c#写的接口测试工具,支持post get put del请求
c#写的http 请求工具,代码注释清晰,希望可以帮到大家
C#通过HTTP协议get、post Webservice,并返回消息
客户端以窗口形式展示、通过HTTP协议Get、Post到Webservice的返回数据,代码简单易懂,非常适合学习参考!代码注释清晰!(IIS配置可参考:http://blog.csdn.net/f_felix/article/details/51934284)
C# WinForm提交表单到网页,并且获取反馈数据
C# WinForm提交表单到网页,并且获取反馈数据


