0

I've been using similar XML Posts with success....just that this one calls for ProofPDF which is a byte array.

How can I populate this XML Tag properly... I'm getting an invalid request at the moment.

    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;
    }
Pinch
  • 4,009
  • 8
  • 40
  • 60
  • 1
    Friends don’t let friends to build XML with string concatenation – Alexei Levenkov May 16 '22 at 16:47
  • Ok Friend @AlexeiLevenkov :) what do you suggest? – Pinch May 16 '22 at 16:53
  • Usually one would use XML serialization, but more involved ways are plenty - https://stackoverflow.com/questions/15083727/how-to-create-xml-in-c-sharp. (Obviously `Array.ToString()` method which the sample in the question shows is of no use to anything at all, it exist just because Array is Object...) – Alexei Levenkov May 17 '22 at 20:57

1 Answers1

0

Don't set the content type, read the docs, and use AddStringBody

request.AddStringBody(xmlString, "application/xml");
var response = await client.PostAsync(request);    
Alexey Zimarev
  • 17,944
  • 2
  • 55
  • 83