WebRequest NameResolutionFailure

送分小仙女□ 提交于 2019-12-14 02:16:37

问题


I'm attempting to write a small screen-scraping tool for statistics aggregation in c#. I have attempted to use this code, (posted many times here but again for detail):

public static string GetPage(string url)
{
    HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
    request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)";
    WebResponse response = (HttpWebResponse) request.GetResponse();

    Stream stream = response.GetResponseStream();
    StreamReader reader = new StreamReader(stream);

    string result = reader.ReadToEnd();

    stream.Dispose();
    reader.Dispose();

    return result;
}

However, some (not all) websites I attempt to connect to that use Ajax or server side includes throw NameResolutionFailure exceptions and cannot read the data.

An example of this is : pgatour stats

I am led to believe the HttpWebRequest class emulates a browser when requesting information so you get the post-generated HTML. Currently, the only way I can read the data is making an iMacro that grabs it from the page source after it runs through the browser. As said before, it works in the browser so I don't think the error is related to a DNS issue and the website does generate a response (.haveresponse is set).

Has anyone else encountered this issue and what did you use tor resolve it?

Thanks.

来源:https://stackoverflow.com/questions/8643950/webrequest-nameresolutionfailure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!