<!DOCTYPE html>
<html>
<head>
	<title>限制IP请求次数</title>
	<style>
		.container {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100vh;
		}
		.btn {
			padding: 10px 20px;
			background-color: #4CAF50;
			color: #fff;
			font-size: 20px;
			border: none;
			border-radius: 5px;
			cursor: pointer;
		}
	</style>
</head>
<body>
	<div class="container">
		<button class="btn" onclick="sendPost()">点击发送Post请求</button>
	</div>
<pre><code>&lt;script&gt;
	function sendPost() {
		const xhr = new XMLHttpRequest();

		// 设置请求方法和请求地址
		xhr.open('POST', 'http://localhost:3000', true);

		// 设置请求头
		xhr.setRequestHeader('Content-Type', 'application/json');

		// 设置请求体
		xhr.send(JSON.stringify({}));

		// 监听请求状态变化
		xhr.onreadystatechange = function() {
			if (xhr.readyState === 4 &amp;&amp; xhr.status === 200) {
				const res = JSON.parse(xhr.responseText);
				alert(res.message);
			}
		}
	}
&lt;/script&gt;
</code></pre>
</body>
</html>
写一个html单网页,居中显示一个按钮,功能为点击发送一个Post 设置单ip一小时之内只能请求3次

原文地址: https://www.cveoy.top/t/topic/skC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录