Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用asp.net中的页面URL以编程方式读取html页面的内容?_C#_Asp.net_Asp.net Mvc - Fatal编程技术网

C# 如何使用asp.net中的页面URL以编程方式读取html页面的内容?

C# 如何使用asp.net中的页面URL以编程方式读取html页面的内容?,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,如何使用asp.net中的页面URL以编程方式读取html页面的内容? 例如,我需要阅读我的facebook url的内容,例如:您必须对相应的url发出HTTP请求并解析响应。我建议使用作为参考,这也有很好的例子 编辑: 下面发布的代码来自特定的帖子: WebRequest request = WebRequest.Create("http://testserver/testpage"); //If the target server requires authentication, you

如何使用asp.net中的页面URL以编程方式读取html页面的内容?
例如,我需要阅读我的facebook url的内容,例如:

您必须对相应的url发出HTTP请求并解析响应。我建议使用作为参考,这也有很好的例子

编辑: 下面发布的代码来自特定的帖子:

WebRequest request = WebRequest.Create("http://testserver/testpage");

//If the target server requires authentication, you have to give some credentials in
//your request object. The way you pass these credentials depends on the authentication
//mechanism of the server...

WebResponse response = request.GetResponse();

Stream dataStream = response.GetResponseStream ();
//use dataStream to read data from the server

response.Close();`

希望我能帮忙

其他人在这方面很幸运,但我建议你发布你迄今为止尝试的内容以及失败的原因。如果你只需要html,请使用WebClient。如果您需要更多定制:HttpWebRequest。如果您还需要解析htmlselect一些数据:htmlagilitypack。顺便说一句,我认为获得facebook页面不是一件小事,也可能很棘手。附言:也可以看看Fiddler,看看网络流量。只有链接的答案是不受欢迎的。也许从你的链接中添加一些代码可以改进这篇文章。@paqogomez我想你是对的。一段代码片段会很有帮助。@PantelisNatsiavas。是的,代码很好用。这对我帮助很大