//TODO: convert to generic FormUrlEncoded request public static async Task <OuoPressRoot> ShortenUrlWithOuoPress(OuoPressRequest bodyObject) { App.httpClient.Timeout = TimeSpan.FromMinutes(5); App.httpClient.BaseAddress = new Uri("http://ouo.press"); using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "/shorten")) { request.Content = new FormUrlEncodedContent(ObjectToKeyValuePair(bodyObject)); using (HttpResponseMessage response = await App.httpClient.SendAsync(request)) { string responseString = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <OuoPressRoot>(responseString)); } } }
public async Task <string> TryOuoPress(string url) { try { var req = new OuoPressRequest() { url = url }; var res = await Request.ShortenUrlWithOuoPress(req); string shortUrl = res.slug; return(shortUrl); } catch (Exception) { return(url); } }