<!DOCTYPE html>
<html lang="en">
<body>
<script>
async function getUrlMimeTypeWithFetchHead(url) {
try {
// 发送 HEAD 请求,仅获取响应头
const response = await fetch(url, {
method: 'HEAD'
});
// 从响应头中获取 Content-Type
const contentType = response.headers.get('Content-Type');
console.log('Content-Type:', contentType);
// 格式可能如下 "application/pdf; qs=0.001" 取分号前面的部分 就是 mimeType
return contentType?.split(';')[0]?.trim() || null
} catch (error) {
console.error('Error fetching Content-Type:', error);
return null;
}
}
getUrlMimeTypeWithFetchHead('https://cdn.openai.com/business-guides-and-resources/a-practical-guide-to-building-agents.pdf');
</script>
</body>
</html>
index.html