怎么post数据到一个网页
2011-02-11 14:30
120 查看
写post参数和需要接受数据的页面地址:
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "PM=" + PM;
postData += ("&BID=" + BID);
postData += ("&BTYPE=" + BTYPE);
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://live.com/baike/BkUpdate.html");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
// Get response
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
string content = reader.ReadToEnd();
Response.Write(content);
页面二用于接收参数
if (Request.Form["PM"] == null || Request.Form["BID"] == null || Request.Form["BTYPE"] == null)
{
Response.Write("Error: Parameter Error!");
return;
}
string pm = (Request.Form["PM"] == null ? "" : Request.Form["PM"].Trim());
string bid = (Request.Form["BID"] == null ? "" : Request.Form["BID"].Trim());
string btype = (Request.Form["BTYPE"] == null ? "" : Request.Form["BTYPE"].Trim());
以上代码已测试并成功
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/iamgrowing/archive/2010/02/04/5289065.aspx
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "PM=" + PM;
postData += ("&BID=" + BID);
postData += ("&BTYPE=" + BTYPE);
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://live.com/baike/BkUpdate.html");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
// Get response
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
string content = reader.ReadToEnd();
Response.Write(content);
页面二用于接收参数
if (Request.Form["PM"] == null || Request.Form["BID"] == null || Request.Form["BTYPE"] == null)
{
Response.Write("Error: Parameter Error!");
return;
}
string pm = (Request.Form["PM"] == null ? "" : Request.Form["PM"].Trim());
string bid = (Request.Form["BID"] == null ? "" : Request.Form["BID"].Trim());
string btype = (Request.Form["BTYPE"] == null ? "" : Request.Form["BTYPE"].Trim());
以上代码已测试并成功
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/iamgrowing/archive/2010/02/04/5289065.aspx
相关文章推荐
- 腾讯云图片鉴黄集成到C# SQL Server 怎么在分页获取数据的同时获取到总记录数 sqlserver 操作数据表语句模板 .NET MVC后台发送post请求 百度api查询多个地址的经纬度的问题 try{}里有一个 return 语句,那么紧跟在这个 try 后的 finally {}里的 code 会 不会被执行,什么时候被执行,在 return 前还是后? js获取某个日期
- C用socket怎么post一个表单到一个网页?
- AFNetworking如何post一个json数据到服务器
- java post数据到网页
- VC弹出IE网页附带POST数据的方法
- PHP的CURL方法curl_setopt()函数案例介绍(抓取网页,POST数据)
- 如果在一个实现类中改变另外一个类中的变量,但是怎么改网页上都没变化的问题。
- 如何把一个数据存到文件系统中?是怎么存的?
- Flash/Flex学习笔记(4):如何打开网页及Get/Post数据
- 我想在windows下移植一个tcp/ip协议栈,所以我要直接操作网卡来发送数据,但是怎么操作呢?
- PHP的cURL库功能简介 抓取网页、POST数据及其他
- WebUSB:一个网页是如何从你的手机中盗窃数据的
- [VB.NET]我打开网页的时候会弹出一个安全信息,然后出现:本页包含安全能容和不安全内容,是否显示不安全内容”请达人指教一下怎么删除这个提示
- 最近在编一个通过代理实现网页模拟点击和POST的Internet程序
- SQLSERVER 触发器 将一个服务器上的数据库中数据插入到另一个服务器上的数据库中怎么做
- 怎么用php post 数据到服务器端,封装的方法,只需要输入url 和 post 数据即可
- 如何使用PHP调用API接口( 如何POST一个JSON格式的数据给Restful服务)
- AFNetworking怎么post x-www-form-urlencoded类型的数据
- 请问dudu,我的blog的首页怎么只能显示一个post了呢?
- (原创)怎么直接建立一个DataTable并且为之添加数据