Esempio n. 1
0
        public HttpClass(SupportedHttpMethods httpMethod, string uri)
        {
            _uri        = new Uri(uri);
            _httpMethod = new HttpMethod(httpMethod.ToString());

            switch (httpMethod)
            {
            case SupportedHttpMethods.GET:
                _action = get;
                break;

            case SupportedHttpMethods.POST:
                _action = post;
                break;

            case SupportedHttpMethods.PUT:
                _action = put;
                break;

            case SupportedHttpMethods.DELETE:
                _action = delete;
                break;

            default:
                throw new InvalidHttpMethodException();
            }
        }
Esempio n. 2
0
        public HttpClass(string uri,
                         SupportedHttpMethods httpMethod,
                         string mediaType = "text/json",
                         string content   = null,
                         Dictionary <string, string> requestHeaders = null,
                         Dictionary <string, string> contentHeaders = null)
        {
            if (content != null)
            {
                this.content = new StringContent(content);
                this.content.Headers.ContentType = new MediaTypeHeaderValue(mediaType);
            }



            this.rqstHeaders = requestHeaders;
            this.cntHeaders  = contentHeaders;

            if (this.rqstHeaders == null)
            {
                this.rqstHeaders = new Dictionary <string, string>();
            }

            if (this.cntHeaders == null)
            {
                this.cntHeaders = new Dictionary <string, string>();
            }

            this.rqstHeaders.Add("Authorization", this.BuildAuthHeader());
            this.rqstHeaders.Add("X-Auth-Token", this.BuildUserTokenHeader());

            this.httpClient = new HttpClient();
            this.uri        = new Uri(uri, UriKind.Absolute);
            this.httpMethod = new HttpMethod(httpMethod.ToString());

            if (ConfigurationManager.AppSettings["TimeOut"] != null)
            {
                this.httpClient.Timeout = new TimeSpan(0, Convert.ToInt16(ConfigurationManager.AppSettings["TimeOut"]), 0);
            }

            switch (httpMethod)
            {
            case SupportedHttpMethods.GET:
                this.action = this.Get;
                break;

            case SupportedHttpMethods.POST:
                this.action = this.Post;
                break;

            case SupportedHttpMethods.PUT:
                this.action = this.Put;
                break;

            case SupportedHttpMethods.DELETE:
                this.action = this.Delete;
                break;

            default:
                throw new InvalidHttpMethodException();
            }
        }