35 lines
1016 B
C#
35 lines
1016 B
C#
|
// The URL of the API or website you want to make a request to
|
||
|
using System;
|
||
|
using System.Net.Http;
|
||
|
using System.Text;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
static class HTTP {
|
||
|
public static async Task<string> get(string url){
|
||
|
using (HttpClient client = new HttpClient())
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
HttpResponseMessage response = await client.GetAsync(url);
|
||
|
|
||
|
if (response.IsSuccessStatusCode)
|
||
|
{
|
||
|
Console.writeLine("SUCCESS\n");
|
||
|
string responseData = await response.Content.ReadAsStringAsync();
|
||
|
|
||
|
return responseData;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Console.WriteLine("Error: " + response.StatusCode);
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
Console.WriteLine("Exception occurred: " + ex.Message);
|
||
|
}
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
}
|