本文整理匯總了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);
}
}