Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么Request.InputStream包含额外字节?_C#_.net_Vb.net_Ashx - Fatal编程技术网

C# 为什么Request.InputStream包含额外字节?

C# 为什么Request.InputStream包含额外字节?,c#,.net,vb.net,ashx,C#,.net,Vb.net,Ashx,我正在将字节数组上载到ASHX处理程序 byte[]serializedRequest=SerializeRequest(); var uri=新的uri(_server.ActionUrl); 使用(WebClient=newWebClient()) { 上传数据(uri,serializedRequest); } 由处理程序接收 Dim str As Stream=context.Request.InputStream Dim转换(str.Length-1)作为字节“这里我有额外的“0”-

我正在将字节数组上载到ASHX处理程序

byte[]serializedRequest=SerializeRequest();
var uri=新的uri(_server.ActionUrl);
使用(WebClient=newWebClient())
{
上传数据(uri,serializedRequest);
}
由处理程序接收

Dim str As Stream=context.Request.InputStream
Dim转换(str.Length-1)作为字节“这里我有额外的“0”-字节
str.Position=0
str.Read(转换,0,转换.长度)
如您所见,我必须执行
str.Length-1
来声明字节数组。这是在发展中。我甚至不知道它在部署时会有什么表现。这个字节来自哪里?这是一种可靠的方法,还是我应该在流的开头添加一些字节来告诉从请求中读取多少字节。InputStream?

Dim x(y)as Byte
实际上意味着“具有上限y的数组(长度=y+1)”()

Dim转换(str.Length)作为字节实际上声明了比您需要的更大的数组,所以
str.Length-1
语句是正确的


实际上没有0值字节,因为
Stream.Read()
不需要将Stream读取到底(检查方法返回值),并将额外的字节保留为默认值(0)。

你完全正确!!这是我的VB故障!非常感谢。