通过HttpWebRequest的无法获取的HTML代码 [英] Can't get HTML code through HttpWebRequest

查看:131
本文介绍了通过HttpWebRequest的无法获取的HTML代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图解析在 HTTP网页的HTML代码://odds.bestbetting。 COM /赛马/今天才能有比赛的名单,等
现在的问题是,我不能够提取网页的HTML代码。下面是函数的C#代码:

I am trying to parse the HTML code of the page at http://odds.bestbetting.com/horse-racing/today in order to have a list of races, etc. The problem is I am not being able to retrieve the HTML code of the page. Here is the C# code of the function:

    public static string Http(string url) {          
            Uri myUri = new Uri(url);
            // Create a 'HttpWebRequest' object for the specified url. 
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri);
            myHttpWebRequest.AllowAutoRedirect = true;
            // Send the request and wait for response.
            HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
            var stream = myHttpWebResponse.GetResponseStream();
            var reader = new StreamReader(stream);
            var html = reader.ReadToEnd();
            // Release resources of response object.
            myHttpWebResponse.Close();

            return html;
    }

当我执行程序调用它抛出的异常的功能。

When I execute the program calling the function it throws an exception on

HttpWebResponse myHttpWebResponse =
(HttpWebResponse)myHttpWebRequest.GetResponse();

HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();

这就是:

无法处理来自HTTP / HTTPS协议到其他不同的人重定向

Cannot handle redirect from HTTP/HTTPS protocols to other dissimilar ones.

我看过的这个问题,但我似乎不会有同样的问题。
我也试过iguring出来的东西用嗅探提琴手的流量,但看不到任何东西的地方它重定向或类似的东西。我只是提取了这两种可能的重定向:odds.bestbetting.com/horse-racing/2011-06-10/byCourse
和odds.bestbetting.com/horse-racing/2011-06-10/byTime,但查询他们产生与上述相同的结果。

I have read this question but I don't seem to have the same problem. I've also tried iguring something out sniffing the traffic with fiddler but can't see anything to where it redirects or something similar. I just have extracted these two possible redirections: odds.bestbetting.com/horse-racing/2011-06-10/byCourse and odds.bestbetting.com/horse-racing/2011-06-10/byTime , but querying them produces the same result as above.

这不是我第一次做这样的事情,但我真的失去了这一点。任何帮助吗?

It's not the first time I do something like this, but I'm really lost on this one. Any help?

谢谢!

推荐答案

有可能一打可能的原因您的问题。

There can be a dozen probable causes for your problem.

其中之一是,从服务器重定向指向一个FTP站点,或者类似的东西。

One of them is that the redirect from the server is pointing to an FTP site, or something like that.

它也成为服务器要求,你不能提供请求一些头。

It can also being that the server require some headers in the request that you're failing to provide.

检查内容的浏览器就送到现场,并试图复制。

Check what a browser would send to the site and try to replicate.

这篇关于通过HttpWebRequest的无法获取的HTML代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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