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://international.us.server12.fileserver.kutayzorlu.com/files/download/2017/01/Hex_RGB4_uuid-fa046b6c-fa2c-4f3e-838c-80ed56faee5c_crc-0.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());
        }
    }
}
           
          


This entry was posted in C# Network. Bookmark the permalink.