本文整理匯總了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);
}
}
}
}