在线POST请求工具 - 轻松发送HTTP POST请求
<!DOCTYPE html>
<html>
<head>
<title>在线POST请求工具 - 轻松发送HTTP POST请求</title>
<meta charset='utf-8'>
<style>
body {
margin: 0;
padding: 0;
background-color: #f2f2f2;
}
h1 {
text-align: center;
margin-top: 50px;
font-size: 36px;
color: #333;
}
form {
width: 50%;
margin: 0 auto;
background-color: #fff;
padding: 30px;
box-shadow: 0 0 10px #ccc;
border-radius: 5px;
margin-top: 50px;
}
label {
display: block;
margin-bottom: 10px;
font-size: 18px;
color: #333;
}
input[type='text'], textarea {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
margin-bottom: 20px;
}
button[type='submit'] {
background-color: #333;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
font-size: 18px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>在线POST请求工具</h1>
<form>
<label for='url'>URL:</label>
<input type='text' id='url' name='url' placeholder='请输入请求的URL'>
<label for='data'>请求数据:</label>
<textarea id='data' name='data' rows='10' placeholder='请输入请求数据'></textarea>
<button type='submit' onclick='sendPostRequest(event)'>发送请求</button>
</form>
<script>
function sendPostRequest(event) {
event.preventDefault();
const url = document.getElementById('url').value;
const data = document.getElementById('data').value;
const xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
xhr.onload = function() {
if (xhr.status === 200) {
alert(xhr.responseText);
} else {
alert('请求失败,错误码:' + xhr.status);
}
}
xhr.send(data);
}
</script>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/kNDJ 著作权归作者所有。请勿转载和采集!