在C#中读取远程Html文件 [英] Read a Remote Html file in C#
本文介绍了在C#中读取远程Html文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用c#读取服务器上存在的HTML,但是显示错误
不支持URI格式
不支持文件的路径
我尝试使用以下代码
Hi,
I want to read the HTML which exists on a server using c# but it shows an error of
URI formats are not supported
The file''s path are not supported
i''ve tried with the following code
using (FileStream fs = new FileStream("http://192.168.0.1/MySite/Default.html", FileMode.Open))
using (FileStream fs = new FileStream(@"192.168.0.1\D:\Web\www\MySite\Default.html", FileMode.Open))
{
if (fs.Length == 0)
{ }
else
{
using (StreamReader sr = new StreamReader(fs))
{
for (int i = 0; i < 2; i++)
{
string temp = "";
while ((temp = sr.ReadLine()) != null)
{
status[i] = temp;
}
}
}
}
}
什么是正确的方法?
请告诉我
提前的Thanx
What is the correct way?
Tell me please
Thanx in Advance
推荐答案
你不能为http://和其他Internet方案做这样的事情。您必须使用类System.Net.WebRequest
和System.Net.HttpWebRequest
来代替。
请查看我过去的答案:
如何从其他网站获取数据 [ ^ ],
从网页获取特定数据 [ ^ ]。
-SA
You cannot do such things for http:// and other cases of Internet scheme. You have to use the classSystem.Net.WebRequest
andSystem.Net.HttpWebRequest
instead.
Please see my past answers:
How to get the data from another site[^],
get specific data from web page[^].
—SA
这篇关于在C#中读取远程Html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文