html 返回的各个状态含义


    100: ('Continue', 'Request received, please continue'),
    101: ('Switching Protocols',
          'Switching to new protocol; obey Upgrade header'),

    200: ('OK', 'Request fulfilled, document follows'),
    201: ('Created', 'Document created, URL follows'),
    202: ('Accepted',
          'Request accepted, processing continues off-line'),
    203: ('Non-Authoritative Information', 'Request fulfilled from cache'),
    204: ('No Content', 'Request fulfilled, nothing follows'),
    205: ('Reset Content', 'Clear input form for further input.'),
    206: ('Partial Content', 'Partial content follows.'),

    300: ('Multiple Choices',
          'Object has several resources -- see URI list'),
    301: ('Moved Permanently', 'Object moved permanently -- see URI list'),
    302: ('Found', 'Object moved temporarily -- see URI list'),
    303: ('See Other', 'Object moved -- see Method and URL list'),
    304: ('Not Modified',
          'Document has not changed since given time'),
    305: ('Use Proxy',
          'You must use proxy specified in Location to access this '
          'resource.'),
    307: ('Temporary Redirect',
          'Object moved temporarily -- see URI list'),

    400: ('Bad Request',
          'Bad request syntax or unsupported method'),
    401: ('Unauthorized',
          'No permission -- see authorization schemes'),
    402: ('Payment Required',
          'No payment -- see charging schemes'),
    403: ('Forbidden',
          'Request forbidden -- authorization will not help'),
    404: ('Not Found', 'Nothing matches the given URI'),
    405: ('Method Not Allowed',
          'Specified method is invalid for this server.'),
    406: ('Not Acceptable', 'URI not available in preferred format.'),
    407: ('Proxy Authentication Required', 'You must authenticate with '
          'this proxy before proceeding.'),
    408: ('Request Timeout', 'Request timed out; try again later.'),
    409: ('Conflict', 'Request conflict.'),
    410: ('Gone',
          'URI no longer exists and has been permanently removed.'),
    411: ('Length Required', 'Client must specify Content-Length.'),
    412: ('Precondition Failed', 'Precondition in headers is false.'),
    413: ('Request Entity Too Large', 'Entity is too large.'),
    414: ('Request-URI Too Long', 'URI is too long.'),
    415: ('Unsupported Media Type', 'Entity body in unsupported format.'),
    416: ('Requested Range Not Satisfiable',
          'Cannot satisfy request range.'),
    417: ('Expectation Failed',
          'Expect condition could not be satisfied.'),

    500: ('Internal Server Error', 'Server got itself in trouble'),
    501: ('Not Implemented',
          'Server does not support this operation'),
    502: ('Bad Gateway', 'Invalid responses from another server/proxy.'),
    503: ('Service Unavailable',
          'The server cannot process the request due to a high load'),
    504: ('Gateway Timeout',
          'The gateway server did not receive a timely response'),
    505: ('HTTP Version Not Supported', 'Cannot fulfill request.'),

### 前端请求返回 HTML 而不是 JSON 的原因 当前端发起 AJAX 请求时,预期接收的是 JSON 数据,但如果接收到的是 HTML,则可能是由于以下几个方面的原因: #### 1. 后端接口路径配置错误 如果前端请求的 URL 不正确,可能会导致访问到其他资源文件(如静态 HTML 页面),而非目标 API 接口。这种情况下,后端会返回对应的静态页面内容[^5]。 #### 2. 后端逻辑异常或未捕获错误 在某些场景下,后端可能因内部逻辑错误而未能正常响应 JSON 数据。例如数据库查询失败或其他运行时异常可能导致后端跳转至错误页面,从而返回 HTML 内容[^2]。 #### 3. 权限校验问题 部分系统会在用户无权限访问某个接口时重定向至登录页或其他提示页面。此时浏览器会加载这些页面的内容作为 HTTP 响应的一部分,最终被前端解析为 HTML 文本。 #### 4. MIME 类型设置不当 即使后端确实返回了 JSON 结构的数据,但由于 Content-Type 设置不正确(比如 `text/html` 或者缺失字段),一些库(像 jQuery 的 $.getJSON 方法)仍可能将其视为非合法 JSON 并尝试按 HTML 解析[^1]。 --- ### 解决方法 针对上述情况可以采取如下措施解决问题: #### 验证请求地址准确性 确认所使用的 API 地址是否指向正确的服务端点,并确保其支持通过 GET/POST 提供所需格式化后的数据集[^4]。 #### 检查服务器日志排查错误 查看应用的日志文件定位是否存在任何潜在的技术难题影响到了正常的业务流程执行过程中的各个环节输出信息以便进一步分析根本原因所在位置以及如何修复它。 #### 客户端增加状态码判断机制 在编写 JavaScript 程序时加入额外的状态检测环节,在获取不到期望类型的回复之前先验证相应代码范围内的有效性再决定后续操作步骤: ```javascript axios.get('/api/data') .then(function(response){ if(typeof response.data === 'object'){ console.log('Data received:',response.data); }else{ throw new Error('Invalid Response Format'); } }) .catch(function(error){ alert(`Error occurred:${error.message}`); }); ``` #### 修改Content-Type头部定义 联系负责维护API文档的服务方人员协商调整HTTP Headers 中关于MediaType描述的部分使其更加贴合实际情况满足客户端需求即application/json;charset=UTF-8形式表达. ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值