[英]C# WebClient.DownloadString to access US site of a URL
我正在將URL傳遞到WebClient.DownloadString(“ http://someurl.com ”)中,以下載頁面的HTML,但它始終下載我所在國家/地區的頁面版本(即http://someurl.com/en-cn )。需要下載美國站點的URL。
這是我調用下載html的函數:
public static String GetHtmlStringWC(string url)
{
string htmlString = string.Empty;
try
{
using (WebClient webClient = new WebClient())
{
try
{
webClient.Headers["User-Agent"] = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15";
WebProxy myProxy = new WebProxy();
myProxy.IsBypassed(new Uri(url));
webClient.Proxy = myProxy;
htmlString = webClient.DownloadString(url);
}
catch (Exception ex)
{
throw;
}
finally
{
webClient.Dispose();
}
}
}
catch (WebException wex)
{
throw;
}
catch (Exception ex)
{
throw;
}
finally { }
return htmlString.Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty);
}
我是否缺少參數? 我需要通過什么才能使其始終下載頁面的美國版本?
如果服務器響應頁面的本地化版本,則您的選擇是:
轉到網站,查看是否有設置語言的選項,如果有,請嘗試在程序中進行設置
嘗試使用代理,VPN,Tor等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.