Example #1
0
        /// <summary>
        /// Initializes a new instance of <see cref="T:WebApiRestService.WebApiClient`1"/> using custom options
        /// </summary>
        /// <param name="options">Custom options to be used</param>
        /// <param name="handler">The desired handler</param>
        /// <exception cref="System.ArgumentNullException" />
        public WebApiClient(WebApiClientOptions options, HttpClientHandler handler)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options", "Options parameter is required");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("options", "Handler parameter is required");
            }

            this.Options = options;
            this.Handler = handler;

            //Set the credentials to access resources, if provided
            handler.Credentials = options.Authentication.Credentials;

            //Creates the httpClient and sets default properties
            this.Client             = new HttpClient(handler);
            this.Client.BaseAddress = new Uri(this.Options.BaseAddress);

            //Sets the default request header properties
            this.Headers = this.Client.DefaultRequestHeaders;
            this.Headers.Accept.Clear();
            this.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(this.Options.ContentType.ToMediaFormat()));
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of <see cref="T:WebApiRestService.WebApiClient`1"/> using custom options
 /// </summary>
 /// <param name="options">Custom options to be used</param>
 /// <exception cref="System.ArgumentNullException" />
 public WebApiClient(WebApiClientOptions options) : this(options, new HttpClientHandler())
 {
 }