43 lines
1.4 KiB
HTML
43 lines
1.4 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>简单CORS测试</title>
|
|
</head>
|
|
<body>
|
|
<h1>简单CORS测试</h1>
|
|
<button onclick="testCORS()">测试CORS</button>
|
|
<div id="result"></div>
|
|
|
|
<script>
|
|
async function testCORS() {
|
|
const result = document.getElementById('result');
|
|
result.innerHTML = '测试中...';
|
|
|
|
try {
|
|
// 测试基础GET请求
|
|
const response = await fetch('http://127.0.0.1:5000/api/health');
|
|
const data = await response.json();
|
|
|
|
result.innerHTML = `
|
|
<h3>✅ CORS测试成功!</h3>
|
|
<p>状态码: ${response.status}</p>
|
|
<p>响应数据: ${JSON.stringify(data)}</p>
|
|
<p>CORS头: ${response.headers.get('Access-Control-Allow-Origin') || '未设置'}</p>
|
|
`;
|
|
} catch (error) {
|
|
result.innerHTML = `
|
|
<h3>❌ CORS测试失败</h3>
|
|
<p>错误: ${error.message}</p>
|
|
<p>请检查API服务器是否启动</p>
|
|
`;
|
|
}
|
|
}
|
|
|
|
// 页面加载时自动测试
|
|
window.onload = () => {
|
|
document.getElementById('result').innerHTML = '点击按钮测试CORS配置';
|
|
};
|
|
</script>
|
|
</body>
|
|
</html> |