Problem with WebResponse
-
I'm trying to pull a list of links from a webpage. I have everything working, but my problem is that if a url has an "&" in it, my code returns it as "& amp;" Here is a snippet of my code:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Url); webRequest.Timeout = 10000; HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); Stream responseStream = webResponse.GetResponseStream(); string responseEncoding = webResponse.ContentEncoding.Trim(); if (responseEncoding.Length == 0) { responseEncoding="us-ascii"; } StreamReader responseReader = new StreamReader(responseStream, System.Text.Encoding.GetEncoding(responseEncoding)); string html = responseReader.ReadToEnd(); responseReader.Close();
I know I can manually remove the "amp;" from the link, but I was hoping there was an easier way -david -
I'm trying to pull a list of links from a webpage. I have everything working, but my problem is that if a url has an "&" in it, my code returns it as "& amp;" Here is a snippet of my code:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Url); webRequest.Timeout = 10000; HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); Stream responseStream = webResponse.GetResponseStream(); string responseEncoding = webResponse.ContentEncoding.Trim(); if (responseEncoding.Length == 0) { responseEncoding="us-ascii"; } StreamReader responseReader = new StreamReader(responseStream, System.Text.Encoding.GetEncoding(responseEncoding)); string html = responseReader.ReadToEnd(); responseReader.Close();
I know I can manually remove the "amp;" from the link, but I was hoping there was an easier way -davidHttpServerUtility has the UrlDecode method that will do the translation. [edit] Since it is a Url, you would think that UrlDecode is the right method, but & would be encoded in %xx format, so HtmlDecode might be the correct method. [/edit]
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
-
HttpServerUtility has the UrlDecode method that will do the translation. [edit] Since it is a Url, you would think that UrlDecode is the right method, but & would be encoded in %xx format, so HtmlDecode might be the correct method. [/edit]
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon