65 lines
1.9 KiB
C#
Raw Normal View History

2024-12-16 21:23:13 +00:00
// See https://aka.ms/new-console-template for more information
using Gtk;
using System;
using System.Net.Http;
using System.Threading.Tasks;
partial class Program {
private static readonly HttpClient client = new HttpClient(){
Timeout = TimeSpan.FromSeconds(10) // Set a timeout to avoid hanging
};
public static async Task<string> get(string url){
try
{
Console.WriteLine("SUCCESS\n " + url);
HttpResponseMessage response = await client.GetAsync("https://google.nl");
Console.WriteLine("SUCCESS3\n " + url);
if (response.IsSuccessStatusCode)
{
string responseData = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseData);
return responseData;
}
else
{
Console.WriteLine("Error: " + response.StatusCode);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception occurred: " + ex.Message);
}
return "zzz";
}
static async Task Main(string[] args){
Application.Init();
var window = new Window("My TEst");
window.SetDefaultSize(320,240);
window.DeleteEvent += (o,e) => Application.Quit();
Console.WriteLine("DID TASK\n");
string result = await HttpHelper.GetContentsAsync("http://localhost:9999");
Console.WriteLine(result);
result = await HttpHelper.GetContentsAsync("http://localhost:9999");
Console.WriteLine(result);
//Console.WriteLine(await DrApi.get_rants("https://www.google.nl"));
Console.WriteLine("DID TASK2\n");
window.ShowAll();
Application.Run();
}
}