You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
726 B

const http = require('http');
const postData = JSON.stringify({ test: 'data' });
const options = {
hostname: 'localhost',
port: 3003,
path: '/api/test/post',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
};
console.log('===== 测试 /api/test/post 接口 =====\n');
const req = http.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log('响应状态码:', res.statusCode);
console.log('响应结果:');
console.log(data);
});
});
req.on('error', (e) => {
console.error('请求失败:', e.message);
});
req.write(postData);
req.end();