客户端如何在 C# 中将二进制数组数据发送到服务器
我正在尝试使用 HttpWebRequest 在 C# 中发布 byteArray。我不想将字节转换为字符串(或 ToBase64String
)。我只想将 byteArray 按原样发送到服务器。假设我的数据
byte[] byteArray = { 0, 1, 5, 4, 0, 1, 55, 0, 1, 5, 4, 0, 1}
应该在后参数中定义什么?
request.ContentType = "application/x-www-form-urlencoded"??? or request.ContentType = "application/octet-stream";???
我想我错过了一些大东西......(顺便说一句,服务器是WampServer(Koana,PHP,MySQL)
谢谢!
I am trying to use the HttpWebRequest
for posting a byteArray at C#. i dont want to convert the bytes to string (or to ToBase64String
). i just want to send the byteArray to the server as is. let say that my data is
byte[] byteArray = { 0, 1, 5, 4, 0, 1, 55, 0, 1, 5, 4, 0, 1}
what should i define at the post parameters?
request.ContentType = "application/x-www-form-urlencoded"??? or request.ContentType = "application/octet-stream";???
I think I am missing something big....(BTW, the server is WampServer (Koana,PHP,MySQL)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更简单的方法是使用
WebClient
:对于二进制数据,您通常会使用
application/octet-stream
- 但这不是必需的(取决于服务器) ),即上面的WebClient
上传没有指定内容类型标头。An easier way to do this would be to use a
WebClient
:For binary data you usually would use
application/octet-stream
- but this is not required (depends on the server), i.e. theWebClient
upload above does not specify a content-type header.