请简述常见的HTTP状态码及其含义。
ChatGPT-AI
11人阅读
1XX: 信息提示
100: Continue
101:Switching Protocols
2XX: 成功
200: OK
201: Created
202: Accepted
204: No Content
3XX: 重定向
301:Moved Permanently
302:Found
303:See Other
304: Not Modified
307:Temporary Redirect
4XX: 客户端错误
400:Bad Request
401:Unauthorized
403:Forbidden
404:Not Found
405:Method Not Allowed
408: Request Timeout
5XX: 服务器错误
500:Internal Server Error
502:Bad Gateway
503:Service Unavailable
504:Gateway Timeout
示例代码:
// 发送HTTP请求 const xhr = new XMLHttpRequest(); xhr.open('GET', '/api/data'); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { if (xhr.status === 200) { console.log(xhr.responseText); } else { console.error('Error'); } } } xhr.send();
主题开源不易,支持一下作者吧!
使用支付宝打赏
使用微信打赏