简体   繁体   English

通过RestSharp发送非多部分数据

[英]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.

相关问题 使用RestSharp发送HTTP POST Multipart / form-data字段 - Sending HTTP POST Multipart/form-data field using RestSharp RestSharp在发送前获取帖子数据 - RestSharp get post data before sending 如何在Restsharp中使用multipart / form-data上传XML文件? - How to upload an XML file using multipart/form-data with Restsharp? RestSharp可以在不使用多部分内容类型的情况下发送二进制数据吗? - Can RestSharp send binary data without using a multipart content type? 使用RestSharp在multipart / form-data POST中包含文件的问题 - Trouble including a file in multipart/form-data POST using RestSharp 从文本为 RestSharp 请求生成多部分表单数据体 - Generating Multipart form data body from text for RestSharp request 如何在restsharp中发送multipart / form-data中的2个参数? - How can i send 2 parameters in multipart/form-data at restsharp? Restsharp 如何在 MultiPart/form-data 请求中为参数指定 ContentType - Restsharp how to specify ContentType for a parameter in a MultiPart/form-data Request restsharp postman 代码多部分发布请求将 0kb 图像发送到 JIRA - restsharp postman code multipart post request sending 0kb images to JIRA 使用 RestSharp 将 JSON 数据从 Logic App 发送到 Function App 到 Eloqua - Sending JSON data from Logic App to Function App to Eloqua with RestSharp
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM