| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- const http = require('http');
- // 测试发送验证码
- const sendCodeData = JSON.stringify({ phone: '13800138000' });
- const sendCodeOptions = {
- hostname: 'localhost',
- port: 3000,
- path: '/api/auth/send-code',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Content-Length': sendCodeData.length
- }
- };
- const req1 = http.request(sendCodeOptions, (res) => {
- let data = '';
- res.on('data', (chunk) => { data += chunk; });
- res.on('end', () => {
- console.log('发送验证码响应:', data);
-
- // 测试登录 (使用刚才获取的验证码 0227)
- const loginData = JSON.stringify({ phone: '13800138000', code: '0227' });
-
- const loginOptions = {
- hostname: 'localhost',
- port: 3000,
- path: '/api/auth/login',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Content-Length': loginData.length
- }
- };
-
- const req2 = http.request(loginOptions, (res2) => {
- let loginResponse = '';
- res2.on('data', (chunk) => { loginResponse += chunk; });
- res2.on('end', () => {
- console.log('登录响应:', loginResponse);
- });
- });
-
- req2.on('error', (e) => console.error('登录请求错误:', e));
- req2.end();
- });
- });
- req1.on('error', (e) => console.error('发送验证码请求错误:', e));
- req1.write(sendCodeData);
- req1.end();
|