locked
How to read a remote web page RRS feed

  • Question

  • User-132227257 posted

    Hello

    I want to Read a page And Show Complete Contetn of web page.

    i used this code:

        private String readHtmlPage(string url)
        {
            String result;
            WebResponse objResponse;
            WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
            try
            {
                objResponse = objRequest.GetResponse();
                using (StreamReader sr =
                new StreamReader(objResponse.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                    // Close and clean up the StreamReader
                    sr.Close();
                }
            }
            catch (Exception e)
            {
                result = e.Message.ToString();
            }
    
            return result;
        }

    But When Fech is Strated Can Not See Picteures. Just can see Text whitout Styles Like:

    http://bitaf1.persiangig.com/2/Fetching.jpg

    I want To read complete content of page Like this:

    http://bitaf1.persiangig.com/2/Fetching2.jpg

    if possible Help Me.

    Best Regards.

    Embarassed

    Wednesday, August 22, 2012 10:20 AM

All replies

  • User-182667613 posted

    Hi..

    The static method below makes an http request for a web page, and the resulting string of html within the http response is captured and returned to the caller.

    [C#]
    
    //System.Net
    //System.IO
    static string GetHtmlPage(string strURL)
    {
    
      String strResult;
      WebResponse objResponse;
      WebRequest objRequest = HttpWebRequest.Create(strURL);
      objResponse = objRequest.GetResponse();
      using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
      {
        strResult = sr.ReadToEnd();
        sr.Close();
      }
      return strResult;
    }
    
    
    Hope this helps.
    Wednesday, August 22, 2012 11:21 AM
  • User-132227257 posted

    Hello

    It Dos Not Work

    pictures Not Shown.

     

    Wednesday, August 22, 2012 12:47 PM
  • User108830567 posted

    Hi,

       Do remember that when a page renders on a domain (mysite.com), the images as well as links may be using a relative path. This means that on the page, the image tags may be set this way <img src="images/logo.png">. If you copy the HTML with the same content and put it on your server (yoursite.com), the relative path of the images will attempt to find the images at this location yoursite.com/images/logo.png. This is probably what you do not want because those images are not on your server.

    You need to replace the relative paths with absolute paths, so when you render the html the images read this mysite.com/images/logo.png. You can do the text replacement using a regular expression.

    Saturday, August 25, 2012 11:26 AM
  • User-132227257 posted

    Tahnks For Your Reply.

    But your Way Does Not Worked in My Country.  When Replaced Links Again Dos not Shown Pictures Because Filtered.

    Actually I want Make A Anti P R O X Y Server.

    Best Regards

    Saturday, August 25, 2012 11:44 AM