本文整理汇总了C#中System.Net.Http.HttpMessageHandler类的典型用法代码示例。如果您正苦于以下问题:C# HttpMessageHandler类的具体用法?C# HttpMessageHandler怎么用?C# HttpMessageHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpMessageHandler类属于System.Net.Http命名空间,在下文中一共展示了HttpMessageHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SplunkContext
/// <summary>
/// Creates an instance of the SplunkViaHttp context
/// </summary>
public SplunkContext(SplunkClient.Scheme scheme, string host, int port, string index, string username, string password, TimeSpan timeout, HttpMessageHandler handler, bool disposeHandler = true)
: base(scheme, host, port, timeout, handler, disposeHandler)
{
Index = index;
Username = username;
Password = password;
}
示例2: DelegatingHandler
protected DelegatingHandler(HttpMessageHandler innerHandler)
{
if (innerHandler == null)
throw new ArgumentNullException ("innerHandler");
InnerHandler = innerHandler;
}
示例3: RetryHandler
/// <summary>
/// Initializes a new instance of the <see cref="RetryHandler" /> class.
/// </summary>
/// <param name="innerHandler">The inner handler. (Usually new HttpClientHandler())</param>
/// <param name="maxRetries">The maximum retries.</param>
/// <param name="retryDelayMilliseconds">The retry delay milliseconds.</param>
/// <param name="logger">The optional logger to log error messages to.</param>
/// <remarks>
/// When only the auth0 token provider is injected, the auth0 token provider should try to extract the client id from the 401 response header.
/// </remarks>
public RetryHandler(HttpMessageHandler innerHandler, uint maxRetries = 1, uint retryDelayMilliseconds = 500, ILogger logger = null)
: base(innerHandler)
{
this.maxRetries = maxRetries;
this.retryDelayMilliseconds = retryDelayMilliseconds;
this.logger = logger;
}
示例4: OAuthMessageHandler
public OAuthMessageHandler(HttpMessageHandler innerHandler, IHmacSha1HashProvider hashProvider, string consumerKey, string consumerSecret, Token oAuthToken)
: base(innerHandler)
{
if (hashProvider == null)
throw new ArgumentNullException("hashProvider");
if (consumerKey == null)
throw new ArgumentNullException("consumerKey");
if (consumerKey.Length == 0)
throw new ArgumentException("Consumer key cannot be empty.", "consumerKey");
if (consumerSecret == null)
throw new ArgumentNullException("consumerSecret");
if (consumerSecret.Length == 0)
throw new ArgumentException("Consumer secret cannot be empty.", "consumerSecret");
if(oAuthToken != null && !oAuthToken.IsValid)
throw new ArgumentException("OAuth token is not valid.", "oAuthToken");
if (consumerKey == null)
throw new ArgumentNullException("consumerKey");
this.hashProvider = hashProvider;
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
this.oAuthToken = oAuthToken;
}
示例5: MapSensorRoutes
/// <summary>
/// Configures API routes to expose sensors.
/// </summary>
/// <param name="configuration">The HTTP configuration.</param>
/// <param name="authorizeRequest">A delegate providing a method to authorize or deny sensor requests.</param>
/// <param name="baseUri">The base URI at which sensors will be routed.</param>
/// <param name="handler">An optional message handler to be invoked when sensors are called.</param>
/// <returns>
/// The updated <see cref="HttpConfiguration" />.
/// </returns>
/// <exception cref="System.ArgumentNullException">configuration
/// or
/// authorizeRequest</exception>
public static HttpConfiguration MapSensorRoutes(
this HttpConfiguration configuration,
Func<HttpActionContext, bool> authorizeRequest,
string baseUri = "sensors",
HttpMessageHandler handler = null)
{
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}
if (authorizeRequest == null)
{
throw new ArgumentNullException(nameof(authorizeRequest));
}
AuthorizeSensorsAttribute.AuthorizeRequest = authorizeRequest;
configuration.Routes.MapHttpRoute(
"Its-Log-Monitoring-Sensors",
baseUri.AppendSegment("{name}"),
defaults: new
{
controller = "Sensor",
name = RouteParameter.Optional
},
constraints: null,
handler: handler);
return configuration;
}
示例6: HttpClient
public HttpClient (HttpMessageHandler handler, bool disposeHandler)
: base (handler, disposeHandler)
{
buffer_size = int.MaxValue;
timeout = TimeoutDefault;
cts = new CancellationTokenSource ();
}
示例7: UseWebApiWithContainer
public static IAppBuilder UseWebApiWithContainer(this IAppBuilder app, HttpConfiguration configuration, HttpMessageHandler dispatcher)
{
IServiceProvider appContainer = app.GetApplicationContainer();
configuration.DependencyResolver = new OwinDependencyResolverWebApiAdapter(appContainer);
HttpServer httpServer = new OwinDependencyScopeHttpServerAdapter(configuration, dispatcher);
return app.UseWebApi(httpServer);
}
示例8: OpenSrsClient
public OpenSrsClient(OpenSrsMode openSrsMode, string username, string apiKey, HttpMessageHandler httpMessageHandler)
{
HttpClient = new HttpClient(httpMessageHandler);
OpenSrsMode = openSrsMode;
Username = username;
ApiKey = apiKey;
}
示例9: Create
/// <summary>
/// Creates an instance of an <see cref="HttpMessageHandler"/> using the <see cref="DelegatingHandler"/> instances
/// provided by <paramref name="handlers"/>.
/// </summary>
/// <param name="handlers">An ordered list of <see cref="DelegatingHandler"/> instances to be invoked as an
/// <see cref="HttpRequestMessage"/> travels up the stack and an <see cref="HttpResponseMessage"/> travels down.</param>
/// <param name="innerChannel">The inner channel represents the destination of the HTTP message channel.</param>
/// <returns>The HTTP message channel.</returns>
public static HttpMessageHandler Create(IEnumerable<DelegatingHandler> handlers, HttpMessageHandler innerChannel)
{
if (innerChannel == null)
{
throw Error.ArgumentNull("innerChannel");
}
if (handlers == null)
{
return innerChannel;
}
// Wire handlers up
HttpMessageHandler pipeline = innerChannel;
foreach (DelegatingHandler handler in handlers)
{
if (handler == null)
{
throw Error.Argument("handlers", SRResources.DelegatingHandlerArrayContainsNullItem, typeof(DelegatingHandler).Name);
}
if (handler.InnerHandler != null)
{
throw Error.Argument("handlers", SRResources.DelegatingHandlerArrayHasNonNullInnerHandler, typeof(DelegatingHandler).Name, "InnerHandler", handler.GetType().Name);
}
handler.InnerHandler = pipeline;
pipeline = handler;
}
return pipeline;
}
示例10: CreatePipeline
/// <summary>
/// Creates an instance of an <see cref="HttpMessageHandler"/> using the <see cref="DelegatingHandler"/> instances
/// provided by <paramref name="handlers"/>. The resulting pipeline can be used to manually create <see cref="HttpClient"/>
/// or <see cref="HttpMessageInvoker"/> instances with customized message handlers.
/// </summary>
/// <param name="innerHandler">The inner handler represents the destination of the HTTP message channel.</param>
/// <param name="handlers">An ordered list of <see cref="DelegatingHandler"/> instances to be invoked as part
/// of sending an <see cref="HttpRequestMessage"/> and receiving an <see cref="HttpResponseMessage"/>.
/// The handlers are invoked in a top-down fashion. That is, the first entry is invoked first for
/// an outbound request message but last for an inbound response message.</param>
/// <returns>The HTTP message channel.</returns>
public static HttpMessageHandler CreatePipeline(HttpMessageHandler innerHandler, IEnumerable<DelegatingHandler> handlers)
{
if (innerHandler == null)
{
throw Error.ArgumentNull("innerHandler");
}
if (handlers == null)
{
return innerHandler;
}
// Wire handlers up in reverse order starting with the inner handler
HttpMessageHandler pipeline = innerHandler;
IEnumerable<DelegatingHandler> reversedHandlers = handlers.Reverse();
foreach (DelegatingHandler handler in reversedHandlers)
{
if (handler == null)
{
throw Error.Argument("handlers", Properties.Resources.DelegatingHandlerArrayContainsNullItem, typeof(DelegatingHandler).Name);
}
if (handler.InnerHandler != null)
{
throw Error.Argument("handlers", Properties.Resources.DelegatingHandlerArrayHasNonNullInnerHandler, typeof(DelegatingHandler).Name, "InnerHandler", handler.GetType().Name);
}
handler.InnerHandler = pipeline;
pipeline = handler;
}
return pipeline;
}
示例11: MakeClient
protected virtual HttpClient MakeClient(HttpMessageHandler handler)
{
return new HttpClient(handler)
{
Timeout = TimeSpan.FromMilliseconds(int.MaxValue) // Longest TimeSpan HttpClient will accept
};
}
示例12: InstagramApi
public InstagramApi(string identifier, string clientId, string clientSecret, string redirectUrl, HttpMessageHandler handler = null)
: base(identifier, clientId, clientSecret, handler)
{
this.TokenUrl = "https://api.instagram.com/oauth/access_token";
this.RedirectUrl = new Uri(redirectUrl);
Scopes = new[] { "basic" };
}
示例13: AsyncClient
public AsyncClient(
string auth,
int timeout,
ProductInfoHeaderValue userAgent,
HttpMessageHandler httpMessageHandler = null
)
{
_httpMessageHandler = httpMessageHandler ?? new HttpClientHandler();
try
{
_httpClient = new HttpClient(_httpMessageHandler)
{
DefaultRequestHeaders =
{
Authorization = new AuthenticationHeaderValue("Basic", auth),
Accept = {new MediaTypeWithQualityHeaderValue("application/json")},
UserAgent = {userAgent}
},
Timeout = TimeSpan.FromMilliseconds(timeout)
};
}
catch
{
_httpClient?.Dispose();
_httpMessageHandler.Dispose();
throw;
}
}
示例14: BaseServerCompressionHandler
/// <summary>
/// Initializes a new instance of the <see cref="ServerCompressionHandler" /> class.
/// </summary>
/// <param name="innerHandler">The inner handler.</param>
/// <param name="contentSizeThreshold">The content size threshold before compressing.</param>
/// <param name="enableCompression">Custom delegate to enable or disable compression.</param>
/// <param name="compressors">The compressors.</param>
protected BaseServerCompressionHandler(HttpMessageHandler innerHandler, int contentSizeThreshold, Predicate<HttpRequestMessage> enableCompression, params ICompressor[] compressors)
{
if (innerHandler != null)
{
this.InnerHandler = innerHandler;
}
this.Compressors = compressors;
this.contentSizeThreshold = contentSizeThreshold;
this.httpContentOperations = new HttpContentOperations();
this.enableCompression = enableCompression ?? (x =>
{
// If request does not accept gzip or deflate, return false
if (x.Headers.AcceptEncoding.All(y => y.Value != "gzip" && y.Value != "deflate"))
{
return false;
}
// If compression has been explicitly disabled, return false
if (x.Properties.ContainsKey("compression:Enable"))
{
bool enable;
bool.TryParse(x.Properties["compression:Enable"].ToString(), out enable);
return enable;
}
return true;
});
}
开发者ID:SneakyMax,项目名称:Microsoft.AspNet.WebApi.MessageHandlers.Compression,代码行数:38,代码来源:BaseServerCompressionHandler.cs
示例15: RedisCacheHandler
/// <summary>
/// Used internally only for unit testing.
/// </summary>
/// <param name="innerHandler">The inner handler to retrieve the content from on cache misses.</param>
/// <param name="cacheExpirationPerHttpResponseCode">A mapping of HttpStatusCode to expiration times. If unspecified takes a default value.</param>
/// <param name="cache">The distributed cache to use.</param>
/// /// <param name="statsProvider">An <see cref="IStatsProvider"/> that records statistic information about the caching behavior.</param>
internal RedisCacheHandler(HttpMessageHandler innerHandler, IDictionary<HttpStatusCode, TimeSpan> cacheExpirationPerHttpResponseCode, IDistributedCache cache,
IStatsProvider statsProvider = null) : base(innerHandler ?? new HttpClientHandler())
{
this.StatsProvider = statsProvider ?? new StatsProvider(nameof(RedisCacheHandler));
this.cacheExpirationPerHttpResponseCode = cacheExpirationPerHttpResponseCode ?? new Dictionary<HttpStatusCode, TimeSpan>();
responseCache = cache;
}