Create GetResponse from WebRequest : Web Crawler « Network « C# / C Sharp






Create GetResponse from WebRequest


using System;
using System.Net;
using System.IO;
using System.Drawing;
using System.Windows.Forms;

public class MainClass {
    public static void Main() {
        string picUri = "http://www.apress.com/img/img05/Hex_RGB4.jpg";
        string htmlUri = "http://www.apress.com";

        WebRequest requestPic = WebRequest.Create(picUri);
        WebRequest requestHtml = WebRequest.Create(htmlUri);

        WebResponse responsePic = requestPic.GetResponse();
        WebResponse responseHtml = requestHtml.GetResponse();

        Image img = Image.FromStream(responsePic.GetResponseStream());

        using (StreamReader r = new StreamReader(responseHtml.GetResponseStream())) {
            Console.WriteLine(r.ReadToEnd());
        }
    }
}
           
       








Related examples in the same category

1.Set the BaseAddress for WebClient
2.Build the DownloadString
3.Download a web page in a thread
4.Output webpage content
5.Check the ContentType
6.MiniCrawler: A skeletal Web crawler