61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
|
// 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(url);
|
|||
|
|
|||
|
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");
|
|||
|
Console.WriteLine(await get("https://www.google.nl"));
|
|||
|
//Console.WriteLine(await DrApi.get_rants("https://www.google.nl"));
|
|||
|
Console.WriteLine("DID TASK2\n");
|
|||
|
|
|||
|
window.ShowAll();
|
|||
|
Application.Run();
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|