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.

67 lines
1.4 KiB

const http = require('http');
function testConnectEndpoint() {
console.log('测试/connect端点...');
const options = {
hostname: 'localhost',
port: 8001,
path: '/api/connect',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(JSON.stringify({ username: '', password: '' }))
}
};
const req = http.request(options, (res) => {
console.log(`状态码: ${res.statusCode}`);
res.setEncoding('utf8');
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log('响应数据:', data);
testContractsEndpoint();
});
});
req.on('error', (e) => {
console.error(`请求失败: ${e.message}`);
});
req.write(JSON.stringify({ username: '', password: '' }));
req.end();
}
function testContractsEndpoint() {
console.log('测试/contracts端点...');
const options = {
hostname: 'localhost',
port: 8001,
path: '/api/contracts',
method: 'GET'
};
const req = http.request(options, (res) => {
console.log(`状态码: ${res.statusCode}`);
res.setEncoding('utf8');
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log('响应数据:', data);
});
});
req.on('error', (e) => {
console.error(`请求失败: ${e.message}`);
});
req.end();
}
testConnectEndpoint();