本文整理汇总了C#中System.Net.WebRequest.GetResponse方法的典型用法代码示例。如果您正苦于以下问题:C# WebRequest.GetResponse方法的具体用法?C# WebRequest.GetResponse怎么用?C# WebRequest.GetResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebRequest
的用法示例。
在下文中一共展示了WebRequest.GetResponse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1:
// Create a new WebRequest Object to the mentioned URL.
WebRequest myWebRequest=WebRequest.Create("http://www.contoso.com");
Console.WriteLine("\nThe Timeout time of the request before setting is : {0} milliseconds",myWebRequest.Timeout);
// Set the 'Timeout' property in Milliseconds.
myWebRequest.Timeout=10000;
// This request will throw a WebException if it reaches the timeout limit before it is able to fetch the resource.
WebResponse myWebResponse=myWebRequest.GetResponse();
示例2: 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.com/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);
}
}