I'm need to use cutt.ly URL shorter API and I followed it documentation and this how I consumed it
class Program
{
private const string URL = "https://cutt.ly/api/api.php";
private static string urlParameters = "?key=ddbbdd323230fbf3e0b9&short=https://www.google.com&name=Test";
static void Main(string[] args)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(URL);
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync(urlParameters).Result;.
if (response.IsSuccessStatusCode)
{
var dataObjects = response.Content.ReadAsAsync().Result;
foreach (var d in dataObjects)
{
Console.WriteLine("{0}", d.ToString());
}
}
else
{
Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
}
client.Dispose();
Console.ReadLine();
}
}
But problem is I'm getting following compiling error.
'HttpContent' does not contain a definition for 'ReadAsAsync' and no accessible extension method 'ReadAsAsync' accepting a first argument of type 'HttpContent' could be found
I'm using .net core. How can I handle this using .net core. I found this question. but I'm not clear it's answers.