这事一个开始加载url的 方法 ,在 加载 完成时发生 webClient_OpenReadCompleted方法:
private void DoWebClient()
{
WebClient webClient = new WebClient();
webClient.OpenReadAsync(new Uri("http://www.cnblogs.com/linzheng"));
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
}
这个方法是url请求完成时调用的,这里读取返回流显示在textBox1:
void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
using (StreamReader reader = new StreamReader(e.Result))
{
string contents = reader.ReadToEnd();
int begin = contents.ToString().IndexOf("<title>");
int end = contents.ToString().IndexOf("</title>");
string note = contents.Substring(contents.ToString().IndexOf("摘要"), 300);
webClientTextBlock.Text = contents.ToString().Substring(begin + 7, end - begin -7);
textBox1.Text = note;
}
}
分享到:
相关推荐
C# WebClient 上传文件 WebClient上传文件至服务器
C# WebClient实现文件下载 示例源码
c#中的WebClient的用法,模拟请求
WebClient jar包
WebClient上传下载源码 我们先在IIS网站中建立一个文件夹,此处为"Mp3",并设置此文件夹相关读写权限。 例1:使用WebClient中的UploadFile方法上传文件。代码如下。使用此方法需要将上传的文件夹权限设置为 IIS来宾...
本篇文章主要介绍了C#中WebClient实现文件下载,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
支持 Session 和 Cookie 的 WebClient
WebClient下载文件展示进度条
webClient 服务器端与客户端配置
使用WebClient的UploadFileAsync、UploadFile、DownloadFile、DownloadFileAsync方法,异步调用服务器上传下载数据。
使用WebClient实现文件下载,进度条反应下载进度。
WebClient的例子,在Eclipse中直接可以运行
C# WEBClient 文件上传下载
基于webClient 的ftp操作,该案例是基于http模式,如果是ftp,直接将http改成ftp即可
下载开箱即用:C#使用WebClient获取网页源文件例子:该例子演示了通过WebClient获取百度首页源文件,并进行UTF8解码,存入一个字符串中。
用WebClient编写整站下载.pdf
本代码通过webclient下载,下载文件支持回调显示进度等。
C# sliverlight 中 WebClient与WebRequest以及HttpWebRequest 的关系
Setup_WebClient(虚拟光驱)
htmlunit webclient下载资源,谨慎运行,我设置的下载是1000次,想做个刷下载量的东西,然并卵