发送列表时的'`'字符和RestSharp请求体

Ale*_*kha 11 c# asp.net generics serialization restsharp

我正在尝试使用RestSharp向我的实体发布请求.

但是我收到一个错误:

"System.Xml.XmlException : The '`' character, hexadecimal value 0x60, 
cannot be included in a name."
Run Code Online (Sandbox Code Playgroud)

我将列表放在查询的正文中.

var strList = new List<string>();
      strList.Add("one");
      strList.Add("two");

restRequest.AddBody(strList);
Run Code Online (Sandbox Code Playgroud)

它似乎不喜欢通用序列化的方式.有没有建议如何将列表传递给请求?

小智 7

add:restRequest.RequestFormat = DataFormat.Json before:restRequest.AddBody(strList);

  • 从 RestSharp 106.5.4 更新到 106.6.3 会导致此错误并且此解决方案不起作用。 (2认同)

Sam*_*hdi 4

您可以使用 Server.HtmlEncode 对字符进行编码并稍后进行解码。