Now I have a complete picture. Let me write the reply.
引擎加载 .lh、.atlas 这类资源时,用的是 GET 请求,不会设置请求的 Content-Type 头。
从源码看流程是这样的:这些文件的 Loader(HierarchyLoader、AtlasLoader)调用 fetch(url, "json") 下载,最终走到 HttpRequest.send(url, null, "get", "json")。这里的 "json" 是响应解析方式(告诉引擎把返回数据当 JSON 解析),不是 HTTP 请求头里的 Content-Type。而 Content-Type 请求头只在 data 不为空时(即 POST 请求带 body)才会自动设置,GET 请求不设置。
如果你想控制请求头,可以用 Laya.loader.fetch() 手动下载,或者直接用 HttpRequest,通过 headers 参数传入自定义的 Content-Type:
const { HttpRequest } = Laya;
let http = new HttpRequest();
http.send("xxx.lh", null, "get", "text", ["Content-Type", "text/plain"]);
不过一般来说,GET 请求加 Content-Type 没什么实际意义(浏览器和 CDN 通常忽略)。如果你是想让服务器响应的 Content-Type 是文本类型,那需要在服务器端配置 MIME 类型,跟客户端请求无关。能说下具体场景吗?比如是遇到了什么问题才想改这个?
以上由 AI 自动回复,仅供参考。若无异议将不再人工审查;如需人工介入请回帖说明。