Код: Выделить всё
private async void CheckStatusButton_Click(object sender, EventArgs e)
{
List urlsToCheck = URLs.Text.Split('\n').ToList();
List statusCodeResults = new List();
foreach (string item in urlsToCheck)
{
using (HttpClientHandler handler = new HttpClientHandler())
{
handler.AllowAutoRedirect = true;
using (HttpClient client = new HttpClient(handler))
{
client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue
{
NoCache = true
};
try
{
using (HttpResponseMessage response = await client.GetAsync(item))
{
if (response.StatusCode.ToString() == string.Empty)
{
break;
}
if ((int)response.StatusCode == 200)
{
}
if ((int)response.StatusCode == 404)
{
}
if ((int)response.StatusCode == 301)
{
}
statusCodeResults.Add(((int)response.StatusCode).ToString());
}
}
catch (Exception ex)
{
statusCodeResults.Add("999" + item.ToString());
continue;
}
}
}
}
foreach (var item in statusCodeResults)
{
statusCodes.AppendText(item + Environment.NewLine);
}
MessageBox.Show("Done");
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... t-requests
Мобильная версия