Csharp/C Sharp by API/System.Net/WebRequest — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 15:31, 26 мая 2010
WebRequest.Create(Uri u)
using System;
using System.Net;
using System.IO;
using System.Text;
class MainClass
{
public static void Main(string[] args)
{
Uri uri = new Uri("http://www.nfex.ru");
WebRequest req = WebRequest.Create(uri);
WebResponse resp = req.GetResponse();
Stream stream = resp.GetResponseStream();
StreamReader sr = new StreamReader(stream);
string s = sr.ReadToEnd();
Console.WriteLine(s);
}
}
WebRequest.GetResponse()
using System;
using System.Drawing;
using System.IO;
using System.Net;
using System.Windows.Forms;
class ImageFromWeb: Form
{
Image image;
public static void Main()
{
Application.Run(new ImageFromWeb());
}
public ImageFromWeb()
{
ResizeRedraw = true;
WebRequest webreq = WebRequest.Create("http://www.yoursite.ru/1.jpg");
WebResponse webres = webreq.GetResponse();
Stream stream = webres.GetResponseStream();
image = Image.FromStream(stream);
stream.Close();
}
protected override void OnPaint(PaintEventArgs pea)
{
DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
}
protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
{
grfx.DrawImage(image, 0, 0);
}
}