Files
nxxmdata/testApi.js

45 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const axios = require('axios');
async function testGovernmentApi() {
try {
console.log('测试政府端行政人员API...');
// 先测试网络连接
console.log('尝试连接到后端服务...');
const response = await axios.get('http://localhost:5352/api/government/admin-staff', {
timeout: 5000
});
console.log('连接成功,后端服务正在运行!');
console.log('状态码:', response.status);
console.log('响应数据结构:', JSON.stringify(Object.keys(response.data), null, 2));
if (response.data && response.data.data) {
console.log(`获取到 ${response.data.data.length} 条行政人员数据`);
console.log('第一条数据示例:', JSON.stringify(response.data.data[0] || '无数据', null, 2));
} else {
console.log('响应数据中没有data字段');
console.log('完整响应数据:', JSON.stringify(response.data, null, 2));
}
console.log('\nAPI测试成功');
} catch (error) {
console.error('\nAPI测试失败:');
if (error.code === 'ECONNREFUSED') {
console.error('错误: 无法连接到后端服务,请检查服务是否已启动。');
console.error('服务地址: http://localhost:5352');
} else if (error.code === 'ETIMEDOUT') {
console.error('错误: 连接超时,请检查网络连接和后端服务状态。');
} else if (error.response) {
console.error('HTTP错误状态码:', error.response.status);
console.error('响应数据:', JSON.stringify(error.response.data, null, 2));
} else if (error.request) {
console.error('没有收到响应:', error.request);
} else {
console.error('请求配置错误:', error.message);
}
console.error('完整错误信息:', error);
}
}
testGovernmentApi();