123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <title>工伤接口简单测试</title>
- <style>
- body { font-family: Arial, sans-serif; margin: 20px; }
- button { padding: 10px 20px; margin: 10px; font-size: 16px; }
- .test-btn { background: #007bff; color: white; border: none; border-radius: 5px; }
- .test-btn:hover { background: #0056b3; }
- .result { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
- .success { background: #d4edda; border-color: #c3e6cb; }
- .error { background: #f8d7da; border-color: #f5c6cb; }
- pre { white-space: pre-wrap; word-break: break-all; }
- </style>
- </head>
- <body>
- <h1>🔧 工伤接口Status 200无响应体问题测试</h1>
-
- <h2>测试步骤</h2>
- <button class="test-btn" onclick="testMode()">1️⃣ 测试模式(跳过DLL调用)</button>
- <button class="test-btn" onclick="normalMode()">2️⃣ 正常模式(调用DLL)</button>
- <button class="test-btn" onclick="clearResults()">🗑️ 清空结果</button>
-
- <div id="results"></div>
- <script>
- const API_URL = 'http://localhost:8321/api/entry/workinjury';
-
- function clearResults() {
- document.getElementById('results').innerHTML = '';
- }
-
- function showResult(title, status, data, time) {
- const resultsDiv = document.getElementById('results');
- const resultDiv = document.createElement('div');
- resultDiv.className = `result ${status === 200 ? 'success' : 'error'}`;
-
- resultDiv.innerHTML = `
- <h3>${title}</h3>
- <p><strong>HTTP状态:</strong> ${status}</p>
- <p><strong>时间:</strong> ${time}</p>
- <p><strong>响应数据:</strong></p>
- <pre>${JSON.stringify(data, null, 2)}</pre>
- `;
-
- resultsDiv.appendChild(resultDiv);
- }
-
- async function makeRequest(title, requestData) {
- const startTime = new Date();
-
- try {
- console.log(`发送请求: ${title}`, requestData);
-
- const response = await fetch(API_URL, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(requestData)
- });
-
- const endTime = new Date();
- const duration = endTime - startTime;
-
- console.log(`收到响应: ${response.status}`, response);
-
- let responseData = null;
- const contentType = response.headers.get('content-type');
-
- if (contentType && contentType.includes('application/json')) {
- try {
- responseData = await response.json();
- console.log('解析JSON成功:', responseData);
- } catch (jsonError) {
- responseData = {
- error: 'JSON解析失败',
- details: jsonError.message,
- contentType: contentType
- };
- console.error('JSON解析失败:', jsonError);
- }
- } else {
- const text = await response.text();
- responseData = {
- error: '非JSON响应',
- contentType: contentType,
- text: text
- };
- console.log('非JSON响应:', text);
- }
-
- showResult(title, response.status, responseData, `${duration}ms`);
-
- // 特殊处理Status 200但无响应体的情况
- if (response.status === 200 && (!responseData || Object.keys(responseData).length === 0)) {
- showResult(`❌ ${title} - 发现Status 200无响应体问题!`, 'ERROR', {
- problem: 'HTTP 200 成功但响应体为空或无效',
- suggestion: '这通常表示C#代码执行过程中发生未捕获异常'
- }, '');
- }
-
- } catch (networkError) {
- console.error('网络错误:', networkError);
- showResult(`❌ ${title} - 网络错误`, 'ERROR', {
- error: networkError.message,
- type: 'NetworkError'
- }, '');
- }
- }
-
- function testMode() {
- makeRequest('测试模式(跳过DLL)', {
- action: 'init',
- test_mode: 'immediate_return',
- config: {
- fixmedinsCode: 'SQ201348',
- fixmedinsName: '沭阳铭和医院',
- interfaceVersion: 'V2.1'
- }
- });
- }
-
- function normalMode() {
- makeRequest('正常模式(调用DLL)', {
- action: 'init',
- config: {
- fixmedinsCode: 'SQ201348',
- fixmedinsName: '沭阳铭和医院',
- interfaceVersion: 'V2.1'
- }
- });
- }
-
- // 页面加载完成后的提示
- document.addEventListener('DOMContentLoaded', function() {
- showResult('📋 测试说明', 'INFO', {
- '步骤1': '先点击"测试模式"按钮,验证基础HTTP通信是否正常',
- '步骤2': '如果测试模式正常,再点击"正常模式"测试DLL调用',
- '预期结果': '测试模式应该立即返回成功,正常模式可能会有DLL相关错误',
- '问题定位': '如果测试模式也返回Status 200无响应体,说明问题在HTTP层面',
- '注意': '确保ThCardReader.exe正在运行并监听8321端口'
- }, '');
- });
- </script>
- </body>
- </html>
|