简体   繁体   English

使用 RestClient 发布带有原始 XML 的文件

[英]Posting a file with a raw XML using RestClient

I've been using similar XML Posts with success....just that this one calls for ProofPDF which is a byte array.我一直在成功使用类似的 XML 帖子......只是这个需要 ProofPDF,它是一个字节数组。

How can I populate this XML Tag properly... I'm getting an invalid request at the moment.如何正确填充此 XML 标记...我目前收到无效请求。

    public async void Post(List<IFormFile> files)
    {
        MemoryStream s = new MemoryStream();
        files[0].CopyTo(s); 

        var client = new RestClient("https://api.2312312312dsa.com/default.asmx");
        var request = new RestRequest();
        request.AddHeader("SOAPAction", "http://api.giuhuiu.com/v20/LifelineStatus_Update");
        request.AddHeader("Content-Type", " text/xml; charset=utf-8");         
        request.AddBody("<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body> <EP_Update xmlns=\"http://api.dddd23432.com\"><Request><Credentials><Username>dddd</Username><Password>dddd</Password><Client>test</Client></Credentials><CustomerID>1234454</CustomerID><Status>APPROVED</Status>" 
            + "<ProofPDF>"+ s.ToArray()+"</ProofPDF>"  //Here is the concerning code           
            + "<Program>Apples</Program>"
            + "</Request></EP_Update></soap:Body></soap:Envelope>", "txt/xml");
        var response = client.PostAsync(request);          
        var m = response.Result;
        return;
    }

Don't set the content type, read the docs, and use AddStringBody不要设置内容类型,阅读文档,使用AddStringBody

request.AddStringBody(xmlString, "application/xml");
var response = await client.PostAsync(request);    

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

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