Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The '`' character and RestSharp request body during sending the list

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?

like image 388
Alex Blokha Avatar asked Aug 20 '13 10:08

Alex Blokha


3 Answers

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

like image 25
Samiey Mehdi Avatar answered Nov 15 '22 16:11

Samiey Mehdi


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

like image 200
relly Avatar answered Nov 15 '22 16:11

relly


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.

like image 2
Vladimir Avatar answered Nov 15 '22 15:11

Vladimir