服务器接收httpwebrequest post的数据问题

无法注销的昵称 2013-06-29 04:11:28
使用httpwebrequest post数据到服务器,只能使用request.inputstream来接收,然后自行解析吗?
使用request.form接收不到任何数据。。。

请指导,谢谢~
代码
string url="http://xxxx.com/test.aspx";
string content = "content=" + HttpUtility.UrlEncodeUnicode("this is a sentence.");
byte[] data = Encoding.UTF8.GetBytes(content);

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentLength = data.Length;
request.ContentType = "text/html";

Stream sw= request.GetRequestStream();
sw.Write(data, 0, data.Length);
sw.Close();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream sr = response.GetResponseStream();
StreamReader reader = new StreamReader(sr);
string resultJson=reader.ReadToEnd();
reader.Close();
sr.Close();
response.Close();

服务器端使用下边的方式得不到任何数据
NameValueCollection coll = Request.Form;
string[] requestarr = coll.AllKeys;

使用 Stream s = Request.InputStream;
StreamReader sr = new StreamReader(s);
string inputstream=sr.ReadToEnd();
sr.Close();
可以得到post来的数据,可是需要自行解析,比较麻烦。。。

有没有比较好的方法?
...全文
269 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jxb_Sir 2013-07-01
  • 打赏
  • 举报
回复
听不懂。
  • 打赏
  • 举报
回复
有没有大侠帮下忙啊~

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧