in common/src/service/HttpClientHelper.cs [547:618]
private Task PostAsyncHelper<T1>(
Uri requestUri,
T1 entity,
TimeSpan operationTimeout,
IDictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>> errorMappingOverrides,
IDictionary<string, string> customHeaders,
MediaTypeHeaderValue customContentType,
ICollection<string> customContentEncoding,
Func<HttpResponseMessage, CancellationToken, Task> processResponseMessageAsync,
CancellationToken cancellationToken)
{
Func<HttpRequestMessage, CancellationToken, Task> modifyRequestMessageFunc = (requestMsg, token) =>
{
AddCustomHeaders(requestMsg, customHeaders);
if (entity != null)
{
if (typeof(T1) == typeof(byte[]))
{
requestMsg.Content = new ByteArrayContent((byte[])(object)entity);
}
else if (typeof(T1) == typeof(string))
{
// only used to send batched messages on Http runtime
requestMsg.Content = new StringContent((string)(object)entity);
requestMsg.Content.Headers.ContentType = new MediaTypeHeaderValue(CommonConstants.BatchedMessageContentType);
}
else
{
string str = JsonConvert.SerializeObject(entity, JsonSerializerSettingsInitializer.GetJsonSerializerSettings());
requestMsg.Content = new StringContent(str, System.Text.Encoding.UTF8, ApplicationJson);
}
}
if (customContentType != null)
{
requestMsg.Content.Headers.ContentType = customContentType;
}
if (customContentEncoding != null && customContentEncoding.Count > 0)
{
foreach (string contentEncoding in customContentEncoding)
{
requestMsg.Content.Headers.ContentEncoding.Add(contentEncoding);
}
}
return Task.FromResult(0);
};
if (operationTimeout != _defaultOperationTimeout && operationTimeout > TimeSpan.Zero)
{
return ExecuteWithCustomOperationTimeoutAsync(
HttpMethod.Post,
new Uri(_baseAddress, requestUri),
operationTimeout,
modifyRequestMessageFunc,
IsMappedToException,
processResponseMessageAsync,
errorMappingOverrides,
cancellationToken);
}
else
{
return ExecuteAsync(
HttpMethod.Post,
new Uri(_baseAddress, requestUri),
modifyRequestMessageFunc,
processResponseMessageAsync,
errorMappingOverrides,
cancellationToken);
}
}