无法在csharp(Ajax)中读取网页 [英] Cannot read webpage in csharp (Ajax)

查看:66
本文介绍了无法在csharp(Ajax)中读取网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我尝试阅读网页,但是它不起作用.
这是来自互联网的代码:

Hi Guys.

I try to read a web page but it does not works.
Here is code from internet:

using System.Net;
using System.IO;
using System.Windows.Forms;

string result = null;
string url = "http://www.devtopics.com";
WebResponse response = null;
StreamReader reader = null;

try
{
 HttpWebRequest request = (HttpWebRequest)WebRequest.Create( url );
 request.Method = "GET";
 response = request.GetResponse();
 reader = new StreamReader( response.GetResponseStream(), Encoding.UTF8 );
 result = reader.ReadToEnd();
}
catch (Exception ex)
{
 // handle error
 MessageBox.Show( ex.Message );
}
finally
{
 if (reader != null)
  reader.Close();
 if (response != null)
  response.Close();
}


我使用此网址http://priceboard.fpts.com.vn/user/stock/hcm3/?s=31&rd=r15332110001
进行了测试 这是一个价格委员会.内容结果是缺少内容数据.

帮我解决.
谢谢高级!.


I tested with this url http://priceboard.fpts.com.vn/user/stock/hcm3/?s=31&rd=r15332110001
It is a Price Board. Content result is lack of content data.

Help me fix it.
Thanks in advanced!.

推荐答案

尝试一下:

Try this:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream() );
StringBuilder builder = new StringBuilder();
do
{
    str = reader.ReadLine();
    if (!string.IsNullOrEmpty(str))
    {
        builder.Append(str);
    }
while(str != null);


尊敬的约翰·西蒙斯
非常感谢您的答复.
我已经测试了您的代码,并且与我上面给出的代码饼具有相同的结果.
我将结果保存到我的hardisk上的html文件中,发现缺少网页中的许多数据.
Dear john Simmons
Thank you very much for your replying.
I have test your code and it has the same result with pie of code i gave above.
I saved result to a html file on my hardisk and saw that it is lack of many data from webpage.


这篇关于无法在csharp(Ajax)中读取网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆