예제 #1
0
        public async Task <FileResponse> CreateFileAsync(string container, string filepath, string content, bool checkExists = true)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            if (filepath == null)
            {
                throw new ArgumentNullException("filepath");
            }

            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            IHttpAddress address = baseAddress.WithResource(container, filepath).WithParameter("check_exist", checkExists);
            IHttpRequest request = new HttpRequest(HttpMethod.Post, address.Build(), baseHeaders.Exclude(HttpHeaders.ContentTypeHeader), content);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            var data = new { file = new List <FileResponse>() };

            return(contentSerializer.Deserialize(response.Body, data).file.First());
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpRequest"/> class.
        /// </summary>
        /// <param name="method">HTTP method.</param>
        /// <param name="url">URL.</param>
        /// <param name="headers">Headers collection.</param>
        public HttpRequest(HttpMethod method, string url, IHttpHeaders headers)
        {
            HttpUtils.CheckUrlString(url);

            if (headers == null)
            {
                throw new ArgumentNullException("headers");
            }

            Method  = method;
            Url     = url;
            Headers = headers.Exclude(HttpHeaders.ContentTypeHeader);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpRequest"/> class.
        /// </summary>
        /// <param name="method">HTTP method.</param>
        /// <param name="url">URL.</param>
        /// <param name="headers">Headers collection.</param>
        public HttpRequest(HttpMethod method, string url, IHttpHeaders headers)
        {
            HttpUtils.CheckUrlString(url);

            if (headers == null)
            {
                throw new ArgumentNullException("headers");
            }

            Method = method;
            Url = url;
            Headers = headers.Exclude(HttpHeaders.ContentTypeHeader);
        }