=波波日志 > Asp.Net/C#/WCF > C# WebRequest Post提交数据=
C# WebRequest Post提交数据
C#使用WebRequest如何Post提交数据,示例代码如下
+展开
-C#
string postStr;
byte[] postBin;
HttpWebRequest request;
HttpWebResponse response;
Stream ioStream;
postStr = "username=showbo&pwd=123456";//键值对
postBin = Encoding.GetEncoding(936).GetBytes(postStr);//注意提交到的网站的编码,现在是gb2312的
request = WebRequest.Create("要POST提交到的url") as HttpWebRequest;
request.Method = "post";
request.KeepAlive = false;
request.AllowAutoRedirect = false;//不允许重定向
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postBin.Length;
ioStream = request.GetRequestStream();
ioStream.Write(postBin, 0, postBin.Length);
ioStream.Flush();
ioStream.Close();
response = request.GetResponse() as HttpWebResponse;
StreamReader reader = new StreamReader(response.GetResponseStream(), gb2312);
string r = reader.ReadToEnd();
reader.Close();
response.Close();
byte[] postBin;
HttpWebRequest request;
HttpWebResponse response;
Stream ioStream;
postStr = "username=showbo&pwd=123456";//键值对
postBin = Encoding.GetEncoding(936).GetBytes(postStr);//注意提交到的网站的编码,现在是gb2312的
request = WebRequest.Create("要POST提交到的url") as HttpWebRequest;
request.Method = "post";
request.KeepAlive = false;
request.AllowAutoRedirect = false;//不允许重定向
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postBin.Length;
ioStream = request.GetRequestStream();
ioStream.Write(postBin, 0, postBin.Length);
ioStream.Flush();
ioStream.Close();
response = request.GetResponse() as HttpWebResponse;
StreamReader reader = new StreamReader(response.GetResponseStream(), gb2312);
string r = reader.ReadToEnd();
reader.Close();
response.Close();
类别:Asp.Net/C#/WCF 作者:波波 日期:2011-11-01 【评论:0】
相关文章
- ·C#模拟自动登录和POST提交的方法
- ·在C#中使用 HttpWebRequest 向网站提交数据
- ·get,post数据长度的限制
- ·用C#使用HttpWebRequest Post数据时如何保持Session
- ·ajax指定为post但是未设置content-type或未指定键时时如何获取提交的内容
- ·C#使用HttpWebRequest提交ASP.NET表单并保持Session和Cookie
- ·C#多线程如何共享数据
- ·C#连接Access数据时总报找不到dbo.mdb的问题
- ·HTTP POST慢速DOS攻击apache
- ·C#2.0中,SerialPort如何读取串口数据并显示在TextBox上
- ·如何提交网站到Dmoz目录/如何向dmoz提交网站
- ·asp提交复选框checkbox值出现空白
暂时没有评论!
发表留言
热门博文
- IE里Cookie跨域不能读取
- web服务因URL意外地以/**结束,请求格式无法识别
- 去掉隐藏asp.net编译出错aspxerrorpath错误参数
- 解决asp.net验证视图状态 MAC 失败
- 找不到System.Web.Script.Services.ScriptService
- 在aspx,ashx页面挂起线程执行
最新博文
- WCF授权-通过扩展自行实现服务授权
- WCF授权-ASP.NET Roles授权[下篇]
- WCF授权-ASP.NET Roles授权[上篇]
- WCF授权-模拟在WCF中的应用
- WCF授权-模拟(Impersonation)与委托(Delegation)
- WCF授权-基于Windows用户组授权[下篇]
随机博文
- ASP.NET AJAX:Timer控件简单使用
- C#.net中MVC架构的应用
- ASP.NET 2.0移动开发之定义设备筛选器(1)
- WCF中的Session和Instancing Management
- 控制软件只能运行一个实例
- DataTable Compute方法
广告商赞助

