simple_test.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>工伤接口简单测试</title>
  6. <style>
  7. body { font-family: Arial, sans-serif; margin: 20px; }
  8. button { padding: 10px 20px; margin: 10px; font-size: 16px; }
  9. .test-btn { background: #007bff; color: white; border: none; border-radius: 5px; }
  10. .test-btn:hover { background: #0056b3; }
  11. .result { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
  12. .success { background: #d4edda; border-color: #c3e6cb; }
  13. .error { background: #f8d7da; border-color: #f5c6cb; }
  14. pre { white-space: pre-wrap; word-break: break-all; }
  15. </style>
  16. </head>
  17. <body>
  18. <h1>🔧 工伤接口Status 200无响应体问题测试</h1>
  19. <h2>测试步骤</h2>
  20. <button class="test-btn" onclick="testMode()">1️⃣ 测试模式(跳过DLL调用)</button>
  21. <button class="test-btn" onclick="normalMode()">2️⃣ 正常模式(调用DLL)</button>
  22. <button class="test-btn" onclick="clearResults()">🗑️ 清空结果</button>
  23. <div id="results"></div>
  24. <script>
  25. const API_URL = 'http://localhost:8321/api/entry/workinjury';
  26. function clearResults() {
  27. document.getElementById('results').innerHTML = '';
  28. }
  29. function showResult(title, status, data, time) {
  30. const resultsDiv = document.getElementById('results');
  31. const resultDiv = document.createElement('div');
  32. resultDiv.className = `result ${status === 200 ? 'success' : 'error'}`;
  33. resultDiv.innerHTML = `
  34. <h3>${title}</h3>
  35. <p><strong>HTTP状态:</strong> ${status}</p>
  36. <p><strong>时间:</strong> ${time}</p>
  37. <p><strong>响应数据:</strong></p>
  38. <pre>${JSON.stringify(data, null, 2)}</pre>
  39. `;
  40. resultsDiv.appendChild(resultDiv);
  41. }
  42. async function makeRequest(title, requestData) {
  43. const startTime = new Date();
  44. try {
  45. console.log(`发送请求: ${title}`, requestData);
  46. const response = await fetch(API_URL, {
  47. method: 'POST',
  48. headers: {
  49. 'Content-Type': 'application/json',
  50. },
  51. body: JSON.stringify(requestData)
  52. });
  53. const endTime = new Date();
  54. const duration = endTime - startTime;
  55. console.log(`收到响应: ${response.status}`, response);
  56. let responseData = null;
  57. const contentType = response.headers.get('content-type');
  58. if (contentType && contentType.includes('application/json')) {
  59. try {
  60. responseData = await response.json();
  61. console.log('解析JSON成功:', responseData);
  62. } catch (jsonError) {
  63. responseData = {
  64. error: 'JSON解析失败',
  65. details: jsonError.message,
  66. contentType: contentType
  67. };
  68. console.error('JSON解析失败:', jsonError);
  69. }
  70. } else {
  71. const text = await response.text();
  72. responseData = {
  73. error: '非JSON响应',
  74. contentType: contentType,
  75. text: text
  76. };
  77. console.log('非JSON响应:', text);
  78. }
  79. showResult(title, response.status, responseData, `${duration}ms`);
  80. // 特殊处理Status 200但无响应体的情况
  81. if (response.status === 200 && (!responseData || Object.keys(responseData).length === 0)) {
  82. showResult(`❌ ${title} - 发现Status 200无响应体问题!`, 'ERROR', {
  83. problem: 'HTTP 200 成功但响应体为空或无效',
  84. suggestion: '这通常表示C#代码执行过程中发生未捕获异常'
  85. }, '');
  86. }
  87. } catch (networkError) {
  88. console.error('网络错误:', networkError);
  89. showResult(`❌ ${title} - 网络错误`, 'ERROR', {
  90. error: networkError.message,
  91. type: 'NetworkError'
  92. }, '');
  93. }
  94. }
  95. function testMode() {
  96. makeRequest('测试模式(跳过DLL)', {
  97. action: 'init',
  98. test_mode: 'immediate_return',
  99. config: {
  100. fixmedinsCode: 'SQ201348',
  101. fixmedinsName: '沭阳铭和医院',
  102. interfaceVersion: 'V2.1'
  103. }
  104. });
  105. }
  106. function normalMode() {
  107. makeRequest('正常模式(调用DLL)', {
  108. action: 'init',
  109. config: {
  110. fixmedinsCode: 'SQ201348',
  111. fixmedinsName: '沭阳铭和医院',
  112. interfaceVersion: 'V2.1'
  113. }
  114. });
  115. }
  116. // 页面加载完成后的提示
  117. document.addEventListener('DOMContentLoaded', function() {
  118. showResult('📋 测试说明', 'INFO', {
  119. '步骤1': '先点击"测试模式"按钮,验证基础HTTP通信是否正常',
  120. '步骤2': '如果测试模式正常,再点击"正常模式"测试DLL调用',
  121. '预期结果': '测试模式应该立即返回成功,正常模式可能会有DLL相关错误',
  122. '问题定位': '如果测试模式也返回Status 200无响应体,说明问题在HTTP层面',
  123. '注意': '确保ThCardReader.exe正在运行并监听8321端口'
  124. }, '');
  125. });
  126. </script>
  127. </body>
  128. </html>