[英]Sending Non Multipart data Via RestSharp
I need to send A POST request that can not be multi-part data, every answer I have seen so far has been to change the http.cs file for RestSharp, but I am not familiar with how to go about this. 我需要发送一个不能是多部分数据的POST请求,到目前为止我看到的每个答案都是为了更改RestSharp的http.cs文件,但我不熟悉如何解决这个问题。
My code: 我的代码:
var POST_LTFSclient = new RestClient("https://xxxx");
var POST_LTFSrequest = new RestRequest(Method.POST);
POST_LTFSrequest.AddHeader("Authorization", "Token " + Token);
POST_LTFSrequest.AddHeader("Accept", "Application/xml");
POST_LTFSrequest.AddHeader("Content-type", "Application/xml");
POST_LTFSrequest.AddFile("content", @"C:\xxx\xxx\xxx.xml");
The last line cannot be just: 最后一行不能只是:
POST_LTFSrequest.AddFile(@"C:\xxx\xxx\xxx.xml");
but because of this every attempt to send Data is always Multi-part. 但正因为如此,每次发送数据的尝试总是多部分的。 Unfortunately the receiving party do not accept this.
不幸的是接收方不接受这个。
Is there anyway to get around this that is easy to implement, if not could some one explain to me how I change Restsharp to allow this as an option. 无论如何要解决这个问题很容易实现,如果没有,有人可以向我解释我如何更改Restsharp以允许这个作为选项。
So it turns out that because RestSharp has changed so much, the answers I have found are all out dated... 所以事实证明,因为RestSharp发生了很大的变化,我发现的答案都已过时......
I was unable to find anymore information on this issue, so I have had to move away from restSharp. 我无法找到关于这个问题的更多信息,所以我不得不离开restSharp。
The solution I have come up with is as follows: 我提出的解决方案如下:
using (WebClient client = new WebClient())
{
client.Headers.Add("Content-Type", "application/xml");
client.Headers.Add("Accept", "application/xml");
client.Headers.Add("Authorization", "Token " + Token);
using (Stream fileStream = File.OpenRead(@"C:\xxx\yyy\zzz.xml"))
using (Stream requestStream = client.OpenWrite(new Uri("https://xxx/yyy/zzz"), "POST"))
{
fileStream.CopyTo(requestStream);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.