C#HttpClient请求无法剪贴(在System.Net和Windows.Web http请求上)

时间:2019-03-06 22:17:39

标签: c# http filter httprequest httpclient

我正在尝试从以下网站上抓取新闻:https://www.livescore.com/soccer/news/

using (Windows.Web.Http.HttpClient client = new Windows.Web.Http.HttpClient())
            {
                    client.DefaultRequestHeaders.Add("User-Agent",
                                 "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident / 6.0)");
                using (Windows.Web.Http.HttpResponseMessage response = await client.GetAsync(new Uri(pageURL)))
                using (Windows.Web.Http.IHttpContent content = response.Content)
                {
                    try
                    {
                        string result = await content.ReadAsStringAsync();
                        Debug.WriteLine(result);
            }
        }
        }

我看到我收到一个包含response的{​​{1}} 由于我在Your browser is out of date or some of its features are disabled上,因此我移至Windows.Web添加certificates,并尝试添加以下UWP

certificates

但是我仍然从服务器上获得相同的HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter(); filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted); filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Expired); filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.IncompleteChain); filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.WrongUsage); filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName); filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.RevocationInformationMissing); filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.RevocationFailure); 。 知道如何绕过这个吗?

编辑:他们确实有不安全的旧服务器http://www.livescore.com/,我想我可以在这里丢弃一切,但新闻不存在。

1 个答案:

答案 0 :(得分:0)

我认为问题是用户代理字符串。您告诉站点您使用的浏览器是Internet Explorer 10。 查看此页面http://www.useragentstring.com/pages/useragentstring.php?name=Internet+Explorer并尝试使用Internet Explorer 11用户代理(在通过ie11浏览器打开该页面以检查其功能之前)