C#读取网页内容Streamreader [英] C# Read webpage content Streamreader
本文介绍了C#读取网页内容Streamreader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在 streamreader 中读取网页的内容
I need to read the content of a webpage in streamreader like
www.example.com
www.example.com
<test>
<sample></sample>
</test>
我明白了:
System.IO.StreamReader StreamReader1 =
new System.IO.StreamReader("www.example.com");
string test = StreamReader1.ReadToEnd();
但是我得到这个错误代码
but i then i get this error code
尝试访问该方法失败:System.IO.StreamReader..ctor(System.String)
Attempt to access the method failed: System.IO.StreamReader..ctor(System.String)
推荐答案
尝试 WebClient,它更简单,您不必担心溪流和河流:
Try a WebClient, it's easier and you don't have to worry about streams and rivers:
using (var client = new WebClient())
{
string result = client.DownloadString("http://www.example.com");
// TODO: do something with the downloaded result from the remote
// web site
}
这篇关于C#读取网页内容Streamreader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文