44 lines
934 B
JavaScript
44 lines
934 B
JavaScript
|
const https = require('http');
|
||
|
|
||
|
const data = JSON.stringify({
|
||
|
email: 'admin@example.com',
|
||
|
password: 'admin123'
|
||
|
});
|
||
|
|
||
|
const options = {
|
||
|
hostname: 'localhost',
|
||
|
port: 3000,
|
||
|
path: '/api/auth/admin-login',
|
||
|
method: 'POST',
|
||
|
headers: {
|
||
|
'Content-Type': 'application/json',
|
||
|
'Content-Length': data.length
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const req = https.request(options, (res) => {
|
||
|
console.log(`状态码: ${res.statusCode}`);
|
||
|
console.log(`响应头: ${JSON.stringify(res.headers)}`);
|
||
|
|
||
|
let body = '';
|
||
|
res.on('data', (chunk) => {
|
||
|
body += chunk;
|
||
|
});
|
||
|
|
||
|
res.on('end', () => {
|
||
|
console.log('响应体:', body);
|
||
|
try {
|
||
|
const jsonResponse = JSON.parse(body);
|
||
|
console.log('解析后的响应:', JSON.stringify(jsonResponse, null, 2));
|
||
|
} catch (e) {
|
||
|
console.log('无法解析JSON响应');
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
req.on('error', (error) => {
|
||
|
console.error('请求错误:', error);
|
||
|
});
|
||
|
|
||
|
req.write(data);
|
||
|
req.end();
|