Мне нужно заранее. Я отправляю HTTP-запрос GET и анализирую HTML-ответ, если HTML-ответ (строка html) содержит некоторую подстроку, я хочу отправить клиентскому приложению (приложение WPF) какое-либо сообщение об ошибке / предупреждение.
В моем решении, если html-строка состоит из некоторой подстроки, я выбрасываю новое исключение, глупо, какое решение подходит для этой проблемы?
код здесь:
class MyClass
{
//.....
private bool SendRp(string postData)
{
bool result = false;
const string parameters = @"&lok=1&rpI=3";
string htmlStringResult = HttpPostReq(
new Uri(string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", PokecUrl.Rp, Account.SessionId, parameters)), postData);
try
{
if (htmlStringResult.ToLower(new CultureInfo("sk-Sk")).Contains("is is empty"))
{
throw new ArgumentException("ID is empty!");
}
if (htmlStringResult.ToLower(new CultureInfo("sk-Sk")).Contains("id does not exist"))
{
throw new ArgumentException("ID does not exist.");
}
if (htmlStringResult.ToLower(new CultureInfo("sk-Sk")).Contains("blocked"))
{
throw new WebException("Your ID is blocked!");
}
if (!htmlStringResult.ToLower(new CultureInfo("sk-Sk")).Contains("message was send"))
{
Match match = Regex.Match(htmlStringResult, @"\bhs=\w{15}\b");
if (match.Success)
{
result = true;
}
else
{
throw new Exception("Some problem");
}
}
return result;
}
catch (Exception exception)
{
throw exception;
}
}
}