本文整理汇总了C#中System.Net.Http.HttpClientHandler.SupportsAllowAutoRedirect方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClientHandler.SupportsAllowAutoRedirect方法的具体用法?C# HttpClientHandler.SupportsAllowAutoRedirect怎么用?C# HttpClientHandler.SupportsAllowAutoRedirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpClientHandler
的用法示例。
在下文中一共展示了HttpClientHandler.SupportsAllowAutoRedirect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TokenProvider
/// <summary>
/// Create a token provider to authenticate against ArcGIS Server
/// </summary>
/// <param name="rootUrl">Made up of scheme://host:port/site</param>
/// <param name="username">ArcGIS Server user name</param>
/// <param name="password">ArcGIS Server user password</param>
/// <param name="serializer">Used to (de)serialize requests and responses</param>
public TokenProvider(String rootUrl, String username, String password, ISerializer serializer)
{
if (String.IsNullOrWhiteSpace(username) || String.IsNullOrWhiteSpace(password))
{
System.Diagnostics.Debug.WriteLine("TokenProvider for '" + RootUrl + "' not initialized as username/password not supplied.");
return;
}
if (serializer == null) throw new ArgumentNullException("serializer", "Serializer has not been set.");
RootUrl = rootUrl.AsRootUrl();
Serializer = serializer;
TokenRequest = new GenerateToken(username, password);
_httpClientHandler = new HttpClientHandler();
if (_httpClientHandler.SupportsAutomaticDecompression)
_httpClientHandler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
if (_httpClientHandler.SupportsUseProxy()) _httpClientHandler.UseProxy = true;
if (_httpClientHandler.SupportsAllowAutoRedirect()) _httpClientHandler.AllowAutoRedirect = true;
if (_httpClientHandler.SupportsPreAuthenticate()) _httpClientHandler.PreAuthenticate = true;
_httpClient = new HttpClient(_httpClientHandler);
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
System.Diagnostics.Debug.WriteLine("Created TokenProvider for " + RootUrl);
}
示例2: TokenProvider
/// <summary>
/// Create a token provider to authenticate against ArcGIS Server
/// </summary>
/// <param name="rootUrl">Made up of scheme://host:port/site</param>
/// <param name="username">ArcGIS Server user name</param>
/// <param name="password">ArcGIS Server user password</param>
/// <param name="serializer">Used to (de)serialize requests and responses</param>
public TokenProvider(String rootUrl, String username, String password, ISerializer serializer)
{
RootUrl = rootUrl.AsRootUrl();
Serializer = serializer;
if (Serializer == null) throw new ArgumentNullException("serializer", "Serializer has not been set.");
TokenRequest = new GenerateToken(username, password);
_httpClientHandler = new HttpClientHandler();
if (_httpClientHandler.SupportsAutomaticDecompression)
_httpClientHandler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
if (_httpClientHandler.SupportsUseProxy()) _httpClientHandler.UseProxy = true;
if (_httpClientHandler.SupportsAllowAutoRedirect()) _httpClientHandler.AllowAutoRedirect = true;
if (_httpClientHandler.SupportsPreAuthenticate()) _httpClientHandler.PreAuthenticate = true;
_httpClient = new HttpClient(_httpClientHandler);
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
示例3: _doDownload
async Task<IHttpTransferResult> _doDownload(DownloadQueueObject obj, IHttpTransferConfig downloadConfig)
{
// add support for Gzip decompression
HttpClient httpClient;
var httpHandler = new HttpClientHandler();
if (downloadConfig.Gzip)
{
if (httpHandler.SupportsAutomaticDecompression)
{
httpHandler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
}
}
if (downloadConfig.AllowRedirect && httpHandler.SupportsAllowAutoRedirect())
{
httpHandler.AllowAutoRedirect = true;
}
else
{
httpHandler.AllowAutoRedirect = false;
}
httpClient = new HttpClient(httpHandler);
if (downloadConfig.Cookies != null)
{
var uri = new Uri(obj.Url);
var cookies = new CookieContainer();
httpHandler.CookieContainer = cookies;
foreach (var c in downloadConfig.Cookies)
{
cookies.Add(uri, new Cookie(c.Key, c.Value));
}
}
using (httpClient)
{
var method = HttpMethod.Get;
switch (obj.Verb)
{
case "GET":
method = HttpMethod.Get;
break;
case "POST":
method = HttpMethod.Post;
break;
case "PUT":
method = HttpMethod.Put;
break;
case "DELETE":
method = HttpMethod.Delete;
break;
}
using (var message = new HttpRequestMessage(method, obj.Url))
{
if (downloadConfig.Headers != null)
{
foreach (var item in downloadConfig.Headers)
{
message.Headers.Add(item.Key, item.Value);
}
}
// Accept-Encoding:
if (downloadConfig.AcceptEncoding != null)
{
//message.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue(""));
message.Headers.Add("Accept-Encoding", downloadConfig.AcceptEncoding);
}
// Accept:
if (!string.IsNullOrWhiteSpace(downloadConfig.Accept))
{
message.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(downloadConfig.Accept));
}
if (!string.IsNullOrWhiteSpace(obj.Data))
{
var content = new StringContent(obj.Data, Encoding.UTF8,
downloadConfig.ContentEncoding ?? "application/json");
message.Content = content;
}
if (obj.ByteData != null)
{
var content = new ByteArrayContent(obj.ByteData, 0, obj.ByteData.Length);
message.Content = content;
}
if (downloadConfig.Auth != null && downloadConfig.AuthScheme != null)
{
//.........这里部分代码省略.........