本文整理汇总了C#中System.Net.WebRequest.Create方法的典型用法代码示例。如果您正苦于以下问题:C# WebRequest.Create方法的具体用法?C# WebRequest.Create怎么用?C# WebRequest.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebRequest
的用法示例。
在下文中一共展示了WebRequest.Create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Uri
Uri ourUri = new Uri(url);
// Create a 'WebRequest' object with the specified url.
WebRequest myWebRequest = WebRequest.Create(url);
// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse();
// Use "ResponseUri" property to get the actual Uri from where the response was attained.
if (ourUri.Equals(myWebResponse.ResponseUri))
Console.WriteLine("\nRequest Url : {0} was not redirected",url);
else
Console.WriteLine("\nRequest Url : {0} was redirected to {1}",url,myWebResponse.ResponseUri);
// Release resources of response object.
myWebResponse.Close();
示例2: Uri
// Create a new 'Uri' object with the specified string.
Uri myUri =new Uri("http://www.contoso.com");
// Create a new request to the above mentioned URL.
WebRequest myWebRequest= WebRequest.Create(myUri);
// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse= myWebRequest.GetResponse();
示例3: 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.java2s.com");
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);
}
}