':'字符,十六进制值0x3A,不能包含在名称中。
我在解析RestSharp POST请求中的XML主体时从API中收到此错误。
我该怎么办?
string xmlBody = "<soap:Envelope" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
" xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">" +
"<soap:Body> " +
"<MainField " +
" xmlns =\"http://www.w3.org\">" +
"<Username>string</Username> " +
"<Password>string</Password> " +
"<FieldPlace> " +
"<Value1>string</Value1> " +
"<Value2>string</Value2> " +
"</FieldPlace> " +
"</MainField> " +
"</soap:Body> " +
"</soap:Envelope>";
requestPost.AddParameter("text/xml", xmlBody, "text/xml" , ParameterType.RequestBody);
这是XML
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<MainField>
xmlns ="http://www.w3.org">
<Username>string</Username>
<Password>string</Password>
<FieldPlace>
<Value1>string</Value1>
<Value2>string</Value2>
</FieldPlace>
</MainField>
</soap:Body>
</soap:Envelope>
请尝试使用此更正后的XML,让我知道它是否适合您。
注意事项:
。
string xmlBody = "<soap:Envelope" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
" xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">" +
"<soap:Body> " +
"<MainField " +
"xmlns=\"http://www.w3.org/2003/05/soap-envelope\" > " +
"<Username>string</Username> " +
"<Password>string</Password> " +
"<FieldPlace> " +
"<Value1>string</Value1> " +
"<Value2>string</Value2> " +
"</FieldPlace> " +
"</MainField> " +
"</soap:Body> " +
"</soap:Envelope>";
我还建议使用其他方法来生成XML字符串,也许是System.Xml.XmlWriter