Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem with WebResponse

Problem with WebResponse

Scheduled Pinned Locked Moved C#
htmlhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xdavidx
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • X xdavidx

      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

      A Offline
      A Offline
      Andy Brummer
      wrote on last edited by
      #2

      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

      X 1 Reply Last reply
      0
      • A Andy Brummer

        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

        X Offline
        X Offline
        xdavidx
        wrote on last edited by
        #3

        Thanks alot for the help andy, thats just what I was looking for. :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups