コード例 #1
0
    /// <summary>
    /// <para>
    /// Returns a cached HttpMessageHandler determined by the purpose.
    /// </para>
    /// <para>
    /// It is recommended to use the CreateClient() method, unless direct access to the handler is needed.
    /// </para>
    /// <para>
    /// Returns a cached handler that is valid for at least two minutes. Behavior is undefined if it is used beyond that time.
    /// </para>
    /// </summary>
    public HttpMessageHandler CreateHandler(HttpClientPurpose purpose)
    {
        var messageHandler = this.CreateMessageHandler(purpose.UniqueName, purpose.MessageHandlerFactory);

        return(messageHandler);
    }
コード例 #2
0
    /// <summary>
    /// <para>
    /// Returns a customized HttpClient, whose message handler is determined by its purpose.
    /// </para>
    /// <para>
    /// Returns a cached client that is valid for at least two minutes. Behavior is undefined if it is used beyond that time.
    /// </para>
    /// </summary>
    public HttpClient CreateClient(HttpClientPurpose purpose)
    {
        var messageHandler = this.CreateHandler(purpose);

        return(new HttpClient(messageHandler, disposeHandler: false));    // Essential to NOT dispose the handler when disposing the client
    }