13

I am trying to Post request with my entities using RestSharp.

But I receive an error:

"System.Xml.XmlException : The '`' character, hexadecimal value 0x60, 
cannot be included in a name."

I am placing the list in the body of the query.

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

restRequest.AddBody(strList);

It seems it doesn't like how the generic is serialized. Is there any advices how the list should be passed to request?

Xavier W.
  • 1,270
  • 3
  • 21
  • 47
Alex Blokha
  • 1,141
  • 2
  • 17
  • 30
  • Please show a short but *complete* example demonstrating the problem. There's too little to go on here. – Jon Skeet Jan 18 '16 at 07:09

3 Answers3

8

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

relly
  • 439
  • 3
  • 3
4

You can use Server.HtmlEncode to encode character and decode later.

Samiey Mehdi
  • 9,184
  • 18
  • 49
  • 63
2

Above version 106.6.x the AddBody() method does not work with Json anymore, even if RequestFormat is set to Json. Also the AddBody() method is marked as depricated and the suggestion is to change it to AddXmlBody() which also does not work (throws the same exception).

The solution is quite simple though: call AddJsonBody() instead and everything works fine.

Vladimir
  • 1,425
  • 16
  • 31