简体   繁体   English

在ASP.NET C#中从HTTP POST请求接收二进制数据

[英]Receiving binary data from HTTP POST Request in ASP.NET C#

This should be very trivial but for reason can't find it. 这应该是非常琐碎的,但是由于某种原因找不到。 I'm posting some binary data to a form in ASP.NET as multipart/form-data and I can see that the request is receive by looking at Request.InputStream : 我将一些二进制数据作为multipart / form-data发布到ASP.NET中的表单,通过查看Request.InputStream可以看到请求已接收:

-------------------------------7cf2a327f01ae Content-Disposition: form-data; ------------------------------- 7cf2a327f01ae内容处置:表格数据; name="DeviceID1" name =“ DeviceID1”

Some binary data 一些二进制数据

-------------------------------7cf2a327f01ae Content-Disposition: form-data; ------------------------------- 7cf2a327f01ae内容处置:表格数据; name="DeviceID2" name =“ DeviceID2”

Some binary data ... 一些二进制数据...

However I can't find how I can retrieve each part as part of the Request.Form (or Request.Params) collection. 但是我找不到如何检索每个部分作为Request.Form(或Request.Params)集合的一部分。 What could be wrong? 有什么事吗 One work around is to use a filename then retrieve from Request.Files but I wonder what is the proper way of getting the content. 一种解决方法是使用文件名,然后从Request.Files中检索,但是我想知道什么是获取内容的正确方法。 Thanks. 谢谢。

Request.Files是检索发布到服务器的二进制数据的唯一方法。

I found that one problem was the line break and that the request should be terminated with a proper separator like this: 我发现一个问题是换行符,并且应使用适当的分隔符来终止请求,如下所示:

-------------------------------7cf2a327f01ae
Content-Disposition: form-data; name="DeviceID1"

Some binary data

-------------------------------7cf2a327f01ae 
Content-Disposition: form-data; name="DeviceID2"

Some binary data
-------------------------------7cf2a327f01ae 

Now the keys appear in Request.Form however this collection is of type string so I decided to use the filename and then get from Request.Files. 现在,密钥出现在Request.Form中,但是此集合的类型为字符串,因此我决定使用文件名,然后从Request.Files获取。 Or I could parse the entire request content completely manually. 或者,我可以完全手动解析整个请求内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM