惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
云风的 BLOG
云风的 BLOG
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
GbyAI
GbyAI
C
Check Point Blog
M
MIT News - Artificial intelligence
T
The Blog of Author Tim Ferriss
Jina AI
Jina AI
博客园 - 【当耐特】
U
Unit 42
月光博客
月光博客
腾讯CDC
Y
Y Combinator Blog
小众软件
小众软件
博客园_首页
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
The GitHub Blog
The GitHub Blog
博客园 - 聂微东
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
T
Tailwind CSS Blog

博客园 - RockyYu

策略模式 unity中的WWW通讯问题 需求分析的方法 用TlbImp.exe生成程序可调用的Dll C++程序引用Dll 查询本地注册表,调用某后缀文件相应的执行程序,并打开文件 windows服务的安装和卸载 FFmpeg和GPL协议 List<T>的排序 XMLHttpRequest的使用方法 错误: 无法生成临时类 图片滚动效果代码 - RockyYu - 博客园 一个不错的给图片添加说明文字的动态层的代码 - RockyYu - 博客园 截取中文字符串的js方法 js调用XML数据生成DIV 迭代器模式(Iterator Pattern) 创建CLR存储过程 JavaScript Boolean (逻辑)对象 - RockyYu JavaScript文件只在IE6下出错(“未结束的字符串常量”)的解决办法。
C#POST数据,HttpWebRequest请求页面,HttpWebResponse返回数据
RockyYu · 2010-05-21 · via 博客园 - RockyYu

C#调用页面POST数据,并得到返回内容的代码:

代码

 1 private string GetResponseData(byte[] postData)
 2         {
 3             HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://XXX.XXX.XXX");
 4             myRequest.Method = "POST";
 5             myRequest.ContentType = "application/x-www-form-urlencoded";
 6             myRequest.ContentLength = postData.Length;
 7 
 8             Stream newStream = myRequest.GetRequestStream();
 9             // Send the data. 
10             newStream.Write(postData, 0, postData.Length);
11             newStream.Close();
12 
13             // Get response 
14             HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
15             StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
16             return reader.ReadToEnd();
17         }