Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public async Task<HttpResponseMessage> CallApiJsonAsync(HttpMethod method, string relativeUrl, object content)
- {
- var request = new HttpRequestMessage(method, relativeUrl);
- if (content != null)
- {
- var json = JsonConvert.SerializeObject(content);
- request.Content = new StringContent(json, Encoding.UTF8, "application/json");
- }
- return await _client.SendAsync(request);
- }
- public async Task<TResult> CallApiJsonAsync<TResult>(HttpMethod method, string relativeUrl, object content) where TResult : class
- {
- var response = await CallApiJsonAsync(method, relativeUrl, content);
- if (response.IsSuccessStatusCode)
- {
- var responseContent = await response.Content.ReadAsStringAsync();
- return JsonConvert.DeserializeObject<TResult>(responseContent);
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement