RestSharp可以在不使用多部分内容类型的情况下发送二进制数据吗? [英] Can RestSharp send binary data without using a multipart content type?
问题描述
我一直在使用 AddParameter
在我的HTTP请求中包括XML正文:
I have been using AddParameter
to include XML bodies in my HTTP requests:
request.AddParameter(contentType, body, ParameterType.RequestBody);
但是,这似乎不适用于非弦乐器。 (出于某种原因,RestSharp的 Http.RequestBody
是字符串。)我尝试使用 AddFile()
,但是我可以即使我只提供了一个对象,也找不到任何避免将文件编码为 multipart / form 的方法。
However, this does not seem to work for non-string bodies. (RestSharp's Http.RequestBody
is a string for some reason.) I tried using AddFile()
, but I can't find any way to avoid encoding the "file" as multipart/form, even if I've only supplied a single object.
I '我完全不反对用弱势反射来解决此问题,但我希望避免修改源代码,只是为了在HTTP请求中发送任意数据。
I'm not at all opposed to underhanded reflection to solve this problem, but I'm hoping to avoid modifying the source just to send arbitrary data in an HTTP request.
编辑:关于我要发送的请求,它们看起来像这样:
regarding the requests I'm trying to send, they just look like this:
PUT ... HTTP/1.1
Accept: application/vnd...
Authorization: Basic ...
Content-Type: application/octet-stream
<arbitrary bytes>
理想情况下,我想使用相同的调用来发送不同的内容类型:
Ideally, I'd like to use the same calls to send a different content type:
PUT ... HTTP/1.1
Accept: application/vnd...
Authorization: Basic ...
Content-Type: application/vnd...
<other arbitrary bytes>
推荐答案
在最新版本中进行了一些修改,允许使用单个文件而无需创建多部分表单请求。这是一个显示和示例的要点:
There have been some modifications made in the latest version that allow a single file to be used without creating a multipart form request. Here is a gist that shows and example:
https:// gist。 github.com/hallem/5faaa6bebde50641e928
这篇关于RestSharp可以在不使用多部分内容类型的情况下发送二进制数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!