Reference Reference reference

HTTP 响应结构参考

HTTP 响应由状态行、响应头、空行和响应体组成,状态码与 Content-Type 决定前端如何处理。

语法

text
HTTP/1.1 200 OK
Content-Type: application/json

{}

最小示例

js
const res = await fetch('/api');
console.log(res.status, res.headers.get('content-type'));

常见错误

  • 只看语法不看运行环境限制。
  • 没有处理错误、权限或兼容性分支。
  • 示例上线前应结合真实浏览器、服务器或 Git 仓库验证。

相关内容