本文整理汇总了C#中Site.GetHttpProxyPool方法的典型用法代码示例。如果您正苦于以下问题:C# Site.GetHttpProxyPool方法的具体用法?C# Site.GetHttpProxyPool怎么用?C# Site.GetHttpProxyPool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Site
的用法示例。
在下文中一共展示了Site.GetHttpProxyPool方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetHttpWebRequest
protected HttpWebRequest GetHttpWebRequest(Request request, Site site, IDictionary headers)
{
if (site == null) return null;
HttpWebRequest httpWebRequest = SelectRequestMethod(request);
httpWebRequest.UserAgent = site.UserAgent ??
"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0Mozilla/5.0 (Windows NT 10.0; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0";
if (site.IsUseGzip)
{
httpWebRequest.Headers.Add("Accept-Encoding", "gzip");
}
// headers
if (headers != null)
{
var enumerator = headers.GetEnumerator();
while (enumerator.MoveNext())
{
var key = enumerator.Key;
var value = enumerator.Value;
httpWebRequest.Headers.Add(key.ToString(), value.ToString());
}
}
// cookie
httpWebRequest = GeneratorCookie(httpWebRequest, site);
//check:
httpWebRequest.Timeout = site.Timeout;
httpWebRequest.ContinueTimeout = site.Timeout;
httpWebRequest.ReadWriteTimeout = site.Timeout;
httpWebRequest.AllowAutoRedirect = true;
if (headers != null)
{
foreach (DictionaryEntry entry in headers)
{
httpWebRequest.Headers.Add(entry.Key.ToString(), entry.Value.ToString());
}
}
if (site.GetHttpProxyPool().Enable)
{
HttpHost host = site.GetHttpProxyFromPool();
httpWebRequest.Proxy = new WebProxy(host.Host, host.Port);
request.PutExtra(Request.Proxy, host);
}
return httpWebRequest;
}