从thepiratebay下载HTML

时间:2014-09-06 17:22:20

标签: c# httprequest

我在这里以及其他网站上搜索过,其中大多数网站的解决方案是设置编码或向用户代理发送请求。

虽然尝试从thepiratebay下载时对我不起作用。 我尝试在标题中添加用户代理(使用whatsmyuseragent),尝试设置编码(对每种可用类型)并尝试发送完整的假标题(启动Web项目并使用请求查看哪些标头正常但是一切都没有用。

编辑:

我得到一些奇怪的胡言乱语,但我无法复制它,因为它没有放大放大

public static string GetPageHTML(string strUrl)
        {
            WebClient wcClient = new WebClient();
            string strHtml = null;

            try
            {
                wcClient.Headers[HttpRequestHeader.CacheControl] = "max-age=0";
                //wcClient.Headers[HttpRequestHeader.Connection] = "keep-alive";
                wcClient.Headers[HttpRequestHeader.Accept] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
                wcClient.Headers[HttpRequestHeader.AcceptEncoding] = "gzip,deflate,sdch";
                wcClient.Headers[HttpRequestHeader.AcceptLanguage] = "en-US,en;q=0.8,he;q=0.6";
                wcClient.Headers[HttpRequestHeader.Host] = "thepiratebay.se";
                wcClient.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.103 Safari/537.36";
                wcClient.Encoding = Encoding.UTF8;
                strHtml = wcClient.DownloadString(strUrl);
            }
            catch (ArgumentException ex)
            {

            }
            catch (Exception ex)
            {

            }

            return (strHtml);
        }

0 个答案:

没有答案