當前位置: 首頁>>代碼示例>>C#>>正文


C# HttpRequestMessage.AddDefaultHeaders方法代碼示例

本文整理匯總了C#中System.Net.Http.HttpRequestMessage.AddDefaultHeaders方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpRequestMessage.AddDefaultHeaders方法的具體用法?C# HttpRequestMessage.AddDefaultHeaders怎麽用?C# HttpRequestMessage.AddDefaultHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Net.Http.HttpRequestMessage的用法示例。


在下文中一共展示了HttpRequestMessage.AddDefaultHeaders方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ExecuteChunkUploadMessage

        private async Task ExecuteChunkUploadMessage(HttpRequestMessage requestMessage)
        {
            await TryPauseAsync(CancellationToken);

            requestMessage.AddDefaultHeaders(Client);

            using(var responseMessage = await GetHttpClient().SendAsync(requestMessage, CancellationToken.GetValueOrDefault(System.Threading.CancellationToken.None)))
            {
                string response = await responseMessage.Content.ReadAsStringAsync();
                try
                {
                    var sfResponse = JsonConvert.DeserializeObject<ShareFileApiResponse<string>>(response);
                    if (sfResponse.Error)
                    {
                        throw new UploadException(sfResponse.ErrorMessage, sfResponse.ErrorCode);
                    }
                }
                catch (JsonSerializationException jEx)
                {
                    if (responseMessage.Content != null)
                    {
                        TryProcessFailedUploadResponse(response);
                    }

                    throw new UploadException("StorageCenter error: " + response, -1, jEx);
                }
            }
        }
開發者ID:wholroyd,項目名稱:ShareFile-NET,代碼行數:28,代碼來源:AsyncScalingFileUploader.cs

示例2: ExecuteChunkUploadMessage

        private void ExecuteChunkUploadMessage(HttpRequestMessage requestMessage)
        {
            TryPause();

            requestMessage.AddDefaultHeaders(Client);

            using (var responseMessage = GetHttpClient().SendAsync(requestMessage).WaitForTask())
            {
                DeserializeShareFileApiResponse<string>(responseMessage);
                //no exception = success?
            }
        }
開發者ID:wholroyd,項目名稱:ShareFile-NET,代碼行數:12,代碼來源:ScalingFileUploader.cs

示例3: FinishUploadAsync

        private async Task<UploadResponse> FinishUploadAsync()
        {
            this.MarkProgressComplete();

            var client = GetHttpClient();
            var finishUri = this.GetFinishUriForThreadedUploads();
            var requestMessage = new HttpRequestMessage(HttpMethod.Get, finishUri);

            requestMessage.Headers.Add("Accept", "application/json");
            requestMessage.AddDefaultHeaders(Client);

            var response = await client.SendAsync(requestMessage);

            return await GetUploadResponseAsync(response);
        }
開發者ID:wholroyd,項目名稱:ShareFile-NET,代碼行數:15,代碼來源:AsyncScalingFileUploader.cs

示例4: FinishUpload

        private UploadResponse FinishUpload()
        {
            MarkProgressComplete();

            var finishUri = GetFinishUriForThreadedUploads();
            var client = GetHttpClient();

            var requestMessage = new HttpRequestMessage(HttpMethod.Get, finishUri);
            requestMessage.Headers.Add("Accept", "application/json");
            requestMessage.AddDefaultHeaders(Client);

            var response = client.SendAsync(requestMessage).WaitForTask();

            return GetUploadResponse(response);
        }
開發者ID:wholroyd,項目名稱:ShareFile-NET,代碼行數:15,代碼來源:ScalingFileUploader.cs

示例5: InternalUploadAsync

        protected override async Task<UploadResponse> InternalUploadAsync()
        {
            int tryCount = 0;
            Stream stream = File.OpenRead();
            while (true)
            {
                try
                {
                    var httpClient = GetHttpClient();

                    using (var requestMessage = new HttpRequestMessage(
                            HttpMethod.Post,
                            GetChunkUriForStandardUploads()))
                    {
                        using (var streamContent = new StreamContentWithProgress(new NoDisposeStream(stream), OnProgress))
                        {
                            requestMessage.AddDefaultHeaders(Client);
                            streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                            requestMessage.Content = streamContent;

                            var responseMessage =
                                await
                                httpClient.SendAsync(
                                    requestMessage,
                                    CancellationToken.GetValueOrDefault(System.Threading.CancellationToken.None));

                            MarkProgressComplete();

                            return await GetUploadResponseAsync(responseMessage);
                        }
                    }
                }
                catch (Exception)
                {
                    if (tryCount >= 3 || !stream.CanSeek)
                    {
                        throw;
                    }
                    else
                    {
                        tryCount += 1;
                        stream.Seek(0, SeekOrigin.Begin);
                    }
                }
            }
        }
開發者ID:wholroyd,項目名稱:ShareFile-NET,代碼行數:46,代碼來源:AsyncStandardFileUploader.cs

示例6: Upload

        public override UploadResponse Upload(Dictionary<string, object> transferMetadata = null)
        {
            SetUploadSpecification();

            int tryCount = 0;
            Stream stream = File.OpenRead();
            while (true)
            {
                try
                {
                    var httpClient = GetHttpClient();

                    using (var requestMessage = new HttpRequestMessage(
                            HttpMethod.Post,
                            GetChunkUriForStandardUploads()))
                    {
                        using (var streamContent = new StreamContentWithProgress(new NoDisposeStream(stream), OnProgress))
                        {
                            requestMessage.AddDefaultHeaders(Client);
                            streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                            requestMessage.Content = streamContent;

                            var responseMessage =
                                httpClient.SendAsync(requestMessage, CancellationToken.None).WaitForTask();

                            MarkProgressComplete();

                            return GetUploadResponse(responseMessage);
                        }
                    }
                }
                catch (Exception)
                {
                    if (tryCount >= 3 || !stream.CanSeek)
                    {
                        throw;
                    }
                    else
                    {
                        tryCount += 1;
                        stream.Seek(0, SeekOrigin.Begin);
                    }
                }
            }
        }
開發者ID:wholroyd,項目名稱:ShareFile-NET,代碼行數:45,代碼來源:StandardFileUploader.cs


注:本文中的System.Net.Http.HttpRequestMessage.AddDefaultHeaders方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。