// 测试创建动态API const http = require('http'); // 测试数据 const testData = { content: '测试发布帖子', images: ['https://example.com/image1.jpg', 'https://example.com/image2.jpg'], topic: '今天你吃蛋了么?' }; // 发送POST请求到主服务器 const options = { hostname: 'localhost', port: 3003, path: '/api/eggbar/posts', method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(JSON.stringify(testData)) } }; const req = http.request(options, (res) => { console.log(`状态码: ${res.statusCode}`); console.log(`响应头: ${JSON.stringify(res.headers)}`); let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log('响应体:', data); console.log('测试完成'); }); }); req.on('error', (e) => { console.error(`请求错误: ${e.message}`); }); // 发送请求体 req.write(JSON.stringify(testData)); req.end(); console.log('正在发送测试请求到 http://localhost:3003/api/eggbar/posts...'); console.log('测试数据:', testData);