asp.net 如何接受post过来的json格式

地菜 2014-06-30 10:02:08
该请求用下面代码保存:

  Request.SaveAs("d:\\ironfe.txt", true);


保存的文件中内容是:

POST /fdfd/fdfdfd HTTP/1.1
Content-Length: 276
Content-Type: application/json
Accept: */*
Host: aaaaa.afaff.com
User-Agent: open robot v1.0

{"code":200,"data":{"result":1,"xfdderId":"11004-20140100356","cpUserInfo":"fdfff","payType":"1","num":"1","cpPrice":"0.01","openId":"15311004124","transTime":"24-06-30 21:30:53","cpOrderId":"3860"},"sign":"e163536bdd37a7cbc7bd8a4ffa2540c0529af854"}




在php中可以用
$GLOBALS['HTTP_RAW_POST_DATA']; 
方便的获取到
...全文
2096 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
dyhzxhn 2014-07-04
  • 打赏
  • 举报
回复
哎 到底怎么才能接收到啊
save4me 2014-07-01
  • 打赏
  • 举报
回复
参考: C# .net equivilent of HTTP_RAW_POST_DATA?

byte[] data = Request.BinaryRead(Request.TotalBytes);
地菜 2014-07-01
  • 打赏
  • 举报
回复
问题补充 : 去进一步了解
地菜 2014-07-01
  • 打赏
  • 举报
回复
引用 7 楼 diaodiaop 的回复:

context.Response.ContentType = "application/json";
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
using (var reader = new System.IO.StreamReader(context.Request.InputStream))
 {
            string xmlData = reader.ReadToEnd();
}
结贴.
这么自信 ,没搞定
地菜 2014-07-01
  • 打赏
  • 举报
回复
引用 3 楼 save4me 的回复:
参考: C# .net equivilent of HTTP_RAW_POST_DATA?

byte[] data = Request.BinaryRead(Request.TotalBytes);
这个看过 ,没解决 ,我发现更加细致的问题所在了 等我补充
-烟花雨季 2014-07-01
  • 打赏
  • 举报
回复
JavaScript: var obj = JSON.parse(data); alert(obj.name);
by_封爱 2014-07-01
  • 打赏
  • 举报
回复

context.Response.ContentType = "application/json";
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
using (var reader = new System.IO.StreamReader(context.Request.InputStream))
 {
            string xmlData = reader.ReadToEnd();
}
结贴.
bwangel 2014-07-01
  • 打赏
  • 举报
回复
Request.InputStream
myhope88 2014-07-01
  • 打赏
  • 举报
回复
C#有专门的json读取类,直接拿过来用就行了
md5e 2014-07-01
  • 打赏
  • 举报
回复
WebService一般是这样的 POST /fdfd/fdfdfd $.ajax({ url: "test_ajax.aspx/Convert", type: "POST", contentType: "application/json", data: '{ "strJson":' + json + '}', success: function (result) { alert(result.d); }, error: function () { alert("error"); } }); [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] [System.Web.Script.Services.ScriptService] public partial class test_ajax : System.Web.UI.Page { [ScriptMethod(ResponseFormat = ResponseFormat.Json), WebMethod(EnableSession = true)] public static string Convert(string strJson)//error { return strJson; } [WebMethod] public static string HelloWorld(string somebody) { return "Hello World"; } }
地菜 2014-06-30
  • 打赏
  • 举报
回复
答非所问呀

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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