67 lines
1.5 KiB
C#
67 lines
1.5 KiB
C#
namespace Backend.Helper;
|
|
|
|
public static class HttpClientHelper
|
|
{
|
|
public static async Task<string> GetHtml(string url, int port)
|
|
{
|
|
using HttpClient client = new();
|
|
|
|
if (port == 80)
|
|
{
|
|
client.BaseAddress = new($"http://{url}");
|
|
}
|
|
else
|
|
{
|
|
client.BaseAddress = new($"https://{url}");
|
|
}
|
|
|
|
client.DefaultRequestHeaders.Accept.Clear();
|
|
|
|
HttpResponseMessage? response = null;
|
|
|
|
try
|
|
{
|
|
response = await client.GetAsync("/");
|
|
}
|
|
catch
|
|
{
|
|
//
|
|
}
|
|
|
|
if (response is null || !response.IsSuccessStatusCode)
|
|
{
|
|
return "";
|
|
}
|
|
|
|
return await response.Content.ReadAsStringAsync();
|
|
}
|
|
|
|
public static async Task<bool> HasRobotsTxt(string url, int port)
|
|
{
|
|
using HttpClient client = new();
|
|
|
|
if (port == 80)
|
|
{
|
|
client.BaseAddress = new($"http://{url}");
|
|
}
|
|
else
|
|
{
|
|
client.BaseAddress = new($"https://{url}");
|
|
}
|
|
|
|
client.DefaultRequestHeaders.Accept.Clear();
|
|
|
|
HttpResponseMessage? response = null;
|
|
|
|
try
|
|
{
|
|
response = await client.GetAsync("/robots.txt");
|
|
}
|
|
catch
|
|
{
|
|
//
|
|
}
|
|
|
|
return response is not null && response.IsSuccessStatusCode;
|
|
}
|
|
} |