输入流在mvc 4 asp.net中 [英] Input stream in mvc 4 asp.net
问题描述
对于MVC 4中的Web API我试图在控制器中获取http resquest post的输入流我总是得到字节数组的长度= 53但是字节数组是空的所以当我转换时它变成了一个字符串我继续得到一个空字符串
这就是我正在使用的:
< pre lang =vb> Dim InStream As Stream
Dim Len 作为 整数
InStream = HttpContext.Current.Request .InputStream
InStream = CType (InStream,Stream)
Len = CInt ( InStream.Length)
Dim ByteArray(Len) As 字节
InStream.Read(ByteArray, 0 ,Len)
Dim js onParam As String
jsonParam = System.Text.Encoding.UTF8.GetString(ByteArray)
i认为它来自这一行:
InStream = HttpContext.Current.Request.InputStream
但我没有找到如何更换它
请注意客户端发送的字符串是一个JSON字符串
任何帮助?
I发现流是在最后,我将必须将其设置为开头
Dim InStream As Stream
Dim Len As Integer
InStream = HttpContext.Current.Request.InputStream
InStream = CType (InStream,Stream)
Len =CInt (InStream.Length)
Dim ByteArray(Len)作为 字节
InStream.Seek( 0 ,SeekOrigin。开始跨度>);
InStream.Read(ByteArray, 0 ,Len)
Dim jsonParam As String
jsonParam = System.Text.Encoding.UTF8.GetString(ByteArray)
for a web API in MVC 4 i'm trying to get the input stream of a http resquest post in the controller i'm always getting the length of the byte array = 53 but the byte array is empty so when i convert it to string i keep getting an empty string
this is what i'm using:
Dim InStream As Stream
Dim Len As Integer
InStream = HttpContext.Current.Request.InputStream
InStream = CType(InStream, Stream)
Len = CInt(InStream.Length)
Dim ByteArray(Len) As Byte
InStream.Read(ByteArray, 0, Len)
Dim jsonParam As String
jsonParam = System.Text.Encoding.UTF8.GetString(ByteArray)
i think it's from this line :
InStream = HttpContext.Current.Request.InputStream
but i did not find how to replace it
note that the string the client is sending is a JSON string
any help?
I found that the stream is at the end, i will have to set it to the beginning
Dim InStream As Stream Dim Len As Integer InStream = HttpContext.Current.Request.InputStream InStream = CType(InStream, Stream) Len = CInt(InStream.Length) Dim ByteArray(Len) As Byte InStream.Seek(0, SeekOrigin.Begin); InStream.Read(ByteArray, 0, Len) Dim jsonParam As String jsonParam = System.Text.Encoding.UTF8.GetString(ByteArray)
这篇关于输入流在mvc 4 asp.net中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!