Полностью код
// Сообщение в лог
project.SendWarningToLog("", "Переподключение сети!", true);
string userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0";
string host = "192.168.8.1";//project.Variables["Host"].Value; // например, 192.168.1.1
// GET запрос
for(int i = 0; i < 2; i++){
var resultGet = ZennoPoster.HttpGet(
"http://" + host + "/html/mobileconnection.html",
"",
"UTF-8",
ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody,
30000,
string.Empty,
userAgent,
true,
5,
AdditionalHeaders: new[] {
"Host: " + host,
"Accept: */*",
"Accept-Language: ru-RU",
"Connection: keep-alive",
"Referer: http://" + host + "/html/home.html"
}
);
// Парсим Set-Cookie и csrf_token
string cookie = Regex.Match(resultGet, @"(?<=Set-Cookie: ).*?(?=
").Value.Trim();
MatchCollection token_match = Regex.Matches(resultGet, @"(@.*?(?="")");
string csrf_token = token_match[1].Value;
// POST Отключение
var resultPost = ZennoPoster.HttpPost(
"http://" + host + "/api/dialup/mobile-dataswitch",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><dataswitch>"+ i.ToString() +"</dataswitch></request>",
"application/x-www-form-urlencoded",
"",
"UTF-8",
ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.BodyOnly,
30000,
cookie,
userAgent,
true,
5,
AdditionalHeaders: new[] {
"Host: " + host,
"Accept: */*",
"Accept-Language: ru-RU",
"Accept-Encoding: gzip, deflate",
"Origin: http://" + host,
"Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
"__RequestVerificationToken: " + csrf_token,
"X-Requested-With: XMLHttpRequest",
"Connection: keep-alive",
"Referer: http://" + host + "/html/mobileconnection.html"
}
);
Thread.Sleep(5000); // пауза между запросом включение - выключениеб 5сек пауза
}
// тут если надо после подождать раскоментируй
// Рандомная пауза
// Random rnd = new Random();
// Thread.Sleep(rnd.Next(7, 11) * 1000);