本文整理汇总了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);
}
}
}
示例2: ExecuteChunkUploadMessage
private void ExecuteChunkUploadMessage(HttpRequestMessage requestMessage)
{
TryPause();
requestMessage.AddDefaultHeaders(Client);
using (var responseMessage = GetHttpClient().SendAsync(requestMessage).WaitForTask())
{
DeserializeShareFileApiResponse<string>(responseMessage);
//no exception = success?
}
}
示例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);
}
示例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);
}
示例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);
}
}
}
}
示例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);
}
}
}
}