当前位置: 首页>>代码示例>>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;未经允许,请勿转载。