So I have a page that is accepting XML through a POST method. Here’s a small bit of the code:
if (Request.ContentType != "text/xml")
throw new HttpException(500, "Unexpected Content Type");
StreamReader stream = new StreamReader(Request.InputStream);
string x = stream.ReadToEnd(); // added to view content of input stream
XDocument xmlInput = XDocument.Load(stream);
I was getting an error, so I converted the stream to a string, just to see if everything was being sent correctly. When I looked at the content, it looked like this:
%3c%3fxml+version%3d%271.0%27+encoding%3d%27UTF-8%27%3f%3e%0d%0a
So I guess I need to decode the stream. The only problem is that I don’t know how I can use HtmlDecode on the stream, and still keep it as a StreamReader object.
Is there any way to do this?
Apparently the client is sending the content as URL-encoded XML. So you need to decode the content like this:
Anyway, the problem is probably on the client side… why is it encoding the XML this way?