c# - RestSharp 请求中的错误?, XML , ':' 字符,十六进制值 0x3A,不能包含在名称中
问题描述
:
字符 十六进制值0x3A
不能包含在名称中。
POST
在解析 RestSharp请求中的 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,并让我知道这是否适合您。
需要注意的几点:
-
- .xmlns 中缺少空格
soap:Envelope element
。
- .xmlns 中缺少空格
-
- 该
MainField
元素在添加命名空间之前已关闭。
- 该
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 string
,也许是System.Xml.XmlWriter
.
推荐阅读
- python - 如何忽略数据框中的 nan 值
- javascript - 为什么这个基本的 VEXFLOW 代码什么也不渲染?
- google-apps-script - 将文件夹中所有工作表的特定范围内的数据合并到主工作表
- javascript - 通过在 javascript 中重新格式化来减少数组
- fortran - Fortran:意图(出)和假定大小的参数
- html - 将线条与浮动保持在一起
- javascript - Vue 中使用 Vuelidate 的验证不起作用
- r - 如何将r中的光栅文件范围从十进制度更改为米?
- java - DataSource 有效连接但 getURL 返回 null?
- angular - 使用 NgRx 选择器为 Angular Reactive Form 设置默认值