首页 新闻 会员 周边

C#如何接受post请求过来的json数据

0
悬赏园豆:10 [已解决问题] 解决于 2014-10-21 10:40

POST http://localhost:3462/json.ashx HTTP/1.1
Host: localhost:3462
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: null
Accept-Encoding: gzip, deflate
Content-Type: application/json; charset=UTF-8
Content-Length: 95
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

{
cmd: 200101,
version: 1,
request: {
cmdId: 0,
appId: 1
}
}

 

-----------------------------------------

以上是我发送的post请求,请问在服务端我怎么接收

{
cmd: 200101, 
version: 1, 
request: {
cmdId: 0, 
appId: 1
}
}

这个json消息体

豆腐欣欣的主页 豆腐欣欣 | 初学一级 | 园豆:76
提问于:2014-09-15 14:35
< >
分享
最佳答案
1

Stream postData = Request.InputStream;
StreamReader sRead = new StreamReader(postData);
string postContent = sRead.ReadToEnd();
sRead.Close();

其中postContent 就是你的josn字符串,

如果是mvc的话,只需要在你的Controllers 方法上面添加 [HttpPost] 就可

[HttpPost]
public string GetPostData(string josnData)

{

   //

}

 

收获园豆:10
blue_sky_alf | 初学一级 |园豆:72 | 2014-09-15 16:14
其他回答(4)
0

是MVC吗?

1、action定义为post(httppost)

2、定义一个model类型

3、action的参数是这个model类型。

519740105 | 园豆:5810 (大侠五级) | 2014-09-15 15:15
0

你把这个JSON串当成一个字符串post过去,然后在ashx页面做解析吧。

传参数的时候最好编码一下,接收页面再解码一下,如果有中文或者特殊符号之类的东西。

Alex_QY1987 | 园豆:1888 (小虾三级) | 2014-09-15 15:22
0

你好,我想请教一下,客户端根据我提供的服务端接口将json  以post方式转发到 服务端接口。请教一下,那么服务端接收json怎么实现。谢谢

boyccc0929 | 园豆:202 (菜鸟二级) | 2015-10-30 11:32

webclient  找资料看看!

支持(0) 反对(0) pecaboooo0 | 园豆:202 (菜鸟二级) | 2015-11-05 11:32
0

谢谢!!!

pecaboooo0 | 园豆:202 (菜鸟二级) | 2015-11-05 11:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册