【发布时间】:2022-07-08 02:09:59
【问题描述】:
我一直在成功使用类似的 XML 帖子......只是这个需要 ProofPDF,它是一个字节数组。
如何正确填充此 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;
}
【问题讨论】:
-
朋友不要让朋友用字符串连接构建XML
-
好的朋友@AlexeiLevenkov :) 你有什么建议?
-
通常会使用 XML 序列化,但更多涉及的方式很多 - stackoverflow.com/questions/15083727/…。 (显然问题中的示例显示的
Array.ToString()方法根本没有任何用处,它的存在只是因为 Array 是 Object...)