本文整理匯總了C#中System.Net.WebClient.OpenRead方法的典型用法代碼示例。如果您正苦於以下問題:C# WebClient.OpenRead方法的具體用法?C# WebClient.OpenRead怎麽用?C# WebClient.OpenRead使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Net.WebClient
的用法示例。
在下文中一共展示了WebClient.OpenRead方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WebClient
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Download home page data.
Console.WriteLine("Accessing {0} ...", uriString);
// Open a stream to point to the data stream coming from the Web resource.
Stream myStream = myWebClient.OpenRead(uriString);
Console.WriteLine("\nDisplaying Data :\n");
StreamReader sr = new StreamReader(myStream);
Console.WriteLine(sr.ReadToEnd());
// Close the stream.
myStream.Close();
示例2: WebClient.OpenRead(String url)
//引入命名空間
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Xml;
using System.IO;
class MainClass
{
static void Main(string[] args)
{
WebClient client = new WebClient();
Stream rssFeedStream = client.OpenRead("http://yourRssFeedURL");
XmlReader reader = XmlReader.Create(rssFeedStream);
reader.MoveToContent();
while (reader.ReadToFollowing("item"))
{
ProcessItem(reader.ReadSubtree());
}
}
static void ProcessItem(XmlReader reader)
{
reader.ReadToFollowing("title");
string title = reader.ReadElementContentAsString("title", reader.NamespaceURI);
reader.ReadToFollowing("link");
string link = reader.ReadElementContentAsString("link", reader.NamespaceURI);
Console.WriteLine("{0}\n\t{1}", title, link);
}
}