I am integrating an app with a service (iContact), that describes its API as “rest-like”. I post XML, and everything works fine… Until I send special characters like æøå – then I get a “bad request” error from the server.
<contacts>
<contact>
<firstname>Søren</firstname>
<lastname>ÆbleTårn</lastname>
</contact>
</contact>
I tried putting firstname and lastname values in cdata, but that did not help.
Is there some encoding I can apply to values (similar to html-encode), or do I need to move in another direction?
I doubt the problem is specific to .Net, but the answer might be, so here is the code I use:
Dim xml as string = GenerateXml()
Dim http As New HttpClient("http://uri.to/rest")
Dim resp As HttpResponseMessage = http.Post(String.Empty, HttpContent.Create(xml))
You can use numeric entities in XML to help with some encoding issues:
But you still have to be sure the server is coded correct to receive, process and store these characters. It’s hard to know where the error is here…