DmitrMakeev commited on
Commit
0770a22
·
verified ·
1 Parent(s): d15cf78

Create test_send.html

Browse files
Files changed (1) hide show
  1. test_send.html +102 -0
test_send.html ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="ru">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Автоотправка запросов</title>
7
+ <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> <!-- Подключаем SweetAlert2 -->
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ text-align: center;
12
+ padding: 20px;
13
+ }
14
+ input, button {
15
+ margin: 10px;
16
+ padding: 10px;
17
+ font-size: 16px;
18
+ }
19
+ #counter {
20
+ font-size: 20px;
21
+ font-weight: bold;
22
+ color: green;
23
+ }
24
+ </style>
25
+ </head>
26
+ <body>
27
+
28
+ <h2>Отправка запросов</h2>
29
+
30
+ <label>URL запроса:</label>
31
+ <input type="text" id="requestUrl" placeholder="Введите URL">
32
+ <br>
33
+
34
+ <label>Задержка (мс):</label>
35
+ <input type="number" id="delayTime" value="500" min="100">
36
+ <br>
37
+
38
+ <button id="startBtn">Старт</button>
39
+ <button id="stopBtn">Стоп</button>
40
+ <br>
41
+
42
+ <p>Отправлено запросов: <span id="counter">0</span></p>
43
+
44
+ <script>
45
+ let intervalId = null; // Переменная для хранения ID интервала
46
+ let count = 0; // Счётчик запросов
47
+
48
+ document.getElementById("startBtn").addEventListener("click", function () {
49
+ const url = document.getElementById("requestUrl").value.trim();
50
+ let delay = parseInt(document.getElementById("delayTime").value, 10);
51
+
52
+ if (!url) {
53
+ Swal.fire("Ошибка", "Введите URL для отправки запросов!", "error");
54
+ return;
55
+ }
56
+
57
+ if (isNaN(delay) || delay < 100) {
58
+ Swal.fire("Ошибка", "Минимальная задержка 100 мс!", "error");
59
+ return;
60
+ }
61
+
62
+ count = 0; // Сбрасываем счётчик
63
+ document.getElementById("counter").textContent = count;
64
+
65
+ Swal.fire({
66
+ title: "Запросы запущены!",
67
+ text: `Будут отправляться каждые ${delay} мс.`,
68
+ icon: "success",
69
+ timer: 2000,
70
+ showConfirmButton: false
71
+ });
72
+
73
+ // Запускаем отправку запросов по таймеру
74
+ intervalId = setInterval(() => {
75
+ fetch(url, { method: "GET" })
76
+ .then(response => {
77
+ if (!response.ok) throw new Error("Ошибка запроса");
78
+ return response.text();
79
+ })
80
+ .then(data => {
81
+ console.log("Ответ сервера:", data);
82
+ count++;
83
+ document.getElementById("counter").textContent = count;
84
+ })
85
+ .catch(error => {
86
+ console.error("Ошибка:", error);
87
+ Swal.fire("Ошибка", "Не удалось отправить запрос!", "error");
88
+ });
89
+ }, delay);
90
+ });
91
+
92
+ document.getElementById("stopBtn").addEventListener("click", function () {
93
+ if (intervalId) {
94
+ clearInterval(intervalId);
95
+ intervalId = null;
96
+ Swal.fire("Остановлено", "Запросы больше не отправляются", "info");
97
+ }
98
+ });
99
+ </script>
100
+
101
+ </body>
102
+ </html>