获取原始请求的ASP.NET MVC [英] Getting the raw Request in ASP.NET MVC

查看:176
本文介绍了获取原始请求的ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要的原始请求字符串。下面是发送到控制器的http请求的一个例子。其实,我需要发布的数据(最后一行)。我怎样才能得到呢?

请注意,我不希望使用自动JSON模型粘合剂。其实,我需要的原始JSON文本

  POST http://www.anUrl.com/CustomExport/Unscheduled HTTP / 1.1
接受:应用/ JSON,文字/ javascript中,* / *; Q = 0.01
内容类型:应用程序/ JSON;字符集= UTF-8
的X请求 - 由于:XMLHtt prequest
引用站点:http://www.anUrl.com/CustomExport
接受语言:EN-US
接受编码:gzip,紧缩
用户代理:Mozilla的/ 5.0(兼容; MSIE 9.0; Windows NT的6.1; WOW64;三叉戟/ 5.0)
主持人:本地主机:8000
内容长度:102
连接:保持活动
杂注:无缓存

{"runId":"1","fileDate":"8/20/2012","orderStartMinDate":"10/02/2012","orderStartMaxDate":"10/02/2012"}
 

这最后一行是我需要的。这不进来

 变种输入=新的StreamReader(Request.InputStream).ReadToEnd();
 

解决方案

在这一点上流已经读到尾。您需要设置回到开始的InputStream的位置之前,你可以自己阅读。

  Request.InputStream.Position = 0;
VAR输入=新的StreamReader(Request.InputStream).ReadToEnd();
 

I need to get the raw request string. Below is an example of the http request sent to the Controller. Actually, I need Post data (last line). How can I get that?

Notice that I don't want to use the automatic JSON model binder. Actually, I need the raw JSON text

POST http://www.anUrl.com/CustomExport/Unscheduled HTTP/1.1
Accept: application/json, text/javascript, */*; q=0.01
Content-Type: application/json; charset=utf-8
X-Requested-With: XMLHttpRequest
Referer: http://www.anUrl.com/CustomExport
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: localhost:8000
Content-Length: 102
Connection: Keep-Alive
Pragma: no-cache

{"runId":"1","fileDate":"8/20/2012","orderStartMinDate":"10/02/2012","orderStartMaxDate":"10/02/2012"}

This last line is what I need. This doesn't come in

var input = new StreamReader(Request.InputStream).ReadToEnd();

解决方案

At that point the stream has already been read to the end. You need to set the position of the InputStream back to the beginning before you can read it yourself.

Request.InputStream.Position = 0;
var input = new StreamReader(Request.InputStream).ReadToEnd();

这篇关于获取原始请求的ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆