0

Response.GetResponseStream() is returning xml with escape characters

<?xml version=\"1.0\" encoding=\"utf-8\"?>

Because of this XmlReader return {None}. Help please?

HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); req.Accept = "*/*"; req.Headers.Add("UA-CPU", "x86"); req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; MS-RTC LM 8)"; HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); XmlTextReader xRead = new XmlTextReader(resp.GetResponseStream());

xRead is {None} if I the call is from client Script Web Service call. When I check the response stream using a StreamReader

StreamReader reader = new StreamReader(resp.GetResponseStream() return reader.ReadToEnd()

I see the escape characters

<?xml version=\"1.0\" encoding=\"utf-8\"?>

Clark
  • 3
  • 5
  • Context would help a lot, e.g. code on how you get the response itself. –  Oct 14 '09 at 22:49
  • You sure that's not just the debugger putting them in? A code snippet would rule that out – Ruben Bartelink Oct 14 '09 at 22:56
  • Are you checking the returned value in the debugger after the StreamReader is constructed, or outputting it to the Console/Form? If you're looking at it in the debugger, it will escape quotes, and there's another underlying problem. –  Oct 14 '09 at 23:09
  • i am looking in the debugger. `StreamReader reader = new StreamReader(resp.GetResponseStream() return reader.ReadToEnd()` The above code returns a valid xml (without escape characters etc) when I call the method from regular page load event. It returns the weird xml if I call the method from a web service which in tur is called from a javascript. – Clark Oct 14 '09 at 23:14
  • As weird as it sounded, it seemed to be a different problem altogether. Xsl File Path, I was sending was errored and it blew up something else. Thanks for trying to help. Appreciate it. – Clark Oct 15 '09 at 00:26
  • I'm getting this, was there a solution? – sambomartin Mar 05 '13 at 16:39

1 Answers1

-1

Without a code sample of how you actually get the response, I would just run a simple String.Replace("\\"", "\"");. It could get inefficient if your responses are large, but that's the quick fix.

  • 1
    you're right that it's the "quick fix", but this sort of bludgeoning-the-values-to-fit-what-you-want-them-to-be-instead-of-figuring-out-why-they're-wrong attitude will get you into a _lot_ of trouble down the road. You should always try to find the source of your bugs rather than just hide them, because they will always come back to bite you if they aren't fixed properly. – rmeador Oct 14 '09 at 23:00
  • This is without a code sample, without actually knowing whats going on, this is the best I can offer with the information he's given me :/ I will update the answer if more information is provided. –  Oct 14 '09 at 23:01