2012-10-02 151 views
17

我需要获取原始请求字符串。以下是发送给Controller的http请求示例。其实,我需要发布数据(最后一行)。我怎么弄到的?获取ASP.NET MVC中的原始请求

请注意,我不想使用自动JSON模型联编程序。其实,我需要原始的JSON文本

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"} 

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

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

回答

21

在这一点上,流已经被读到最后。在您自己阅读之前,您需要将InputStream的位置设回到开头。

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

谢谢,问题恰恰在于 –