public async Task <ShortUrlList> CreateShortUrl(ShortUrlRequest shortUrlRequest) { var url = GetFunctionUrl("UrlShortener"); CancellationToken cancellationToken; using var client = new HttpClient(); using var request = new HttpRequestMessage(HttpMethod.Post, url); using var httpContent = CreateHttpContent(shortUrlRequest); request.Content = httpContent; using var response = await client .SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken) .ConfigureAwait(false); var resultList = response.Content.ReadAsStringAsync().Result; return(JsonConvert.DeserializeObject <ShortUrlList>(resultList)); }
public async Task <ShortUrlList> CreateShortUrl(ShortUrlRequest shortUrlRequest) { var url = GetFunctionUrl("UrlShortener"); CancellationToken cancellationToken; using (var client = new HttpClient()) using (var request = new HttpRequestMessage(HttpMethod.Post, url)) using (var httpContent = CreateHttpContent(shortUrlRequest)) { request.Content = httpContent; using (var response = await client .SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken) .ConfigureAwait(false)) { return(await GetUrlList()); } } }