protected virtual HttpContent ResolveHttpContent <TContent>( TContent content, IHttpContentResolver httpContentResolver = null) { HttpContent httpContent = null; if (!EqualityComparer <TContent> .Default.Equals(content, default(TContent))) { if (content is HttpContent) { httpContent = content as HttpContent; } else { if (httpContentResolver != null) { httpContent = httpContentResolver.ResolveHttpContent(content); } else { var contentAsDictionary = content as Dictionary <string, string>; httpContent = contentAsDictionary != null ? new DictionaryContentResolver().ResolveHttpContent(content as Dictionary <string, string>) : _restApiClientOptions.DefaultContentResolver.ResolveHttpContent(content); } } } return(httpContent); }
internal HttpContent ResolveHttpContent <TContent>(TContent content, IHttpContentResolver contentResolver = null) { HttpContent httpContent = null; if (content != null) { if (content is HttpContent) { httpContent = content as HttpContent; } else { if (contentResolver != null) { httpContent = contentResolver.ResolveHttpContent(content); } else { var contentAsDictionary = content as Dictionary <string, string>; httpContent = contentAsDictionary != null ? new DictionaryContentResolver().ResolveHttpContent(content as Dictionary <string, string>) : HttpContentResolver.ResolveHttpContent(content); } } } return(httpContent); }
public async Task <TResult> PostAsync <TContent, TResult>(Priority priority, string path, TContent content = default(TContent), IHttpContentResolver contentResolver = null) { var httpClient = GetWebApiClient(priority); SetHttpRequestHeaders(httpClient); HttpContent httpContent = null; if (content != null) { if (content is HttpContent) { httpContent = content as HttpContent; } else { if (contentResolver != null) { httpContent = contentResolver.ResolveHttpContent(content); } else { if (content is Dictionary <string, string> ) { httpContent = new DictionaryContentResolver().ResolveHttpContent(content as Dictionary <string, string>); } else { httpContent = HttpContentResolver.ResolveHttpContent(content); } } } } var response = await httpClient .PostAsync(path, httpContent) .ConfigureAwait(false); if (!await response.EnsureSuccessStatusCodeAsync()) { return(default(TResult)); } return(await HttpResponseResolver.ResolveHttpResponseAsync <TResult>(response)); }