HTTP错误代码大全:详解2xx到5xx

需积分: 9 2 下载量 18 浏览量 更新于2024-10-12 收藏 3KB TXT 举报
"HTTP错误代码集合" HTTP错误代码是网络通信中用来表示客户端或服务器端在处理请求时遇到的问题的三位数字代码。这些错误代码帮助开发者和用户理解为什么某些网页无法正常加载或操作无法完成。以下是一些常见的HTTP错误代码及其含义: 1. **2xx 成功** - `200 OK`:服务器成功处理了请求。 - `201 Created`:POST请求成功,资源已创建。 - `202 Accepted`:服务器已接受请求,但处理尚未完成。 - `204 No Content`:请求成功,但响应中不包含任何数据。 2. **3xx 重定向** - `301 Moved Permanently`:资源已被永久移动到新的URL。 - `302 Found`:临时重定向,请求应通过不同的URI进行。 - `303 See Other`:与302类似,但建议使用GET方法。 - `304 Not Modified`:资源未修改,客户端可以使用缓存的版本。 - `305 Use Proxy`:客户端必须通过指定的代理来访问请求的资源。 - `306 (Unused)`:不再使用,但在旧规范中曾用于多代理重定向。 3. **4xx 客户端错误** - `400 Bad Request`:请求无效,可能是因为格式错误或缺少必需字段。 - `401 Unauthorized`:请求需要有效的身份验证凭证。 - `402 Payment Required`:预留状态码,目前未在HTTP中使用。 - `403 Forbidden`:服务器理解请求,但拒绝执行,可能因为权限不足。 - `404 Not Found`:请求的资源不存在。 - `407 Proxy Authentication Required`:客户端需要通过代理服务器进行身份验证。 - `415 Unsupported Media Type`:请求实体的媒体类型不受服务器支持。 4. **5xx 服务器错误** - `500 Internal Server Error`:服务器遇到意外情况,无法完成请求。 - `501 Not Implemented`:服务器不支持请求的方法。 - `502 Bad Gateway`:服务器作为网关或代理,收到了无效响应。 - `503 Service Unavailable`:服务器暂时过载或维护,无法处理请求。 - `504 Gateway Timeout`:作为网关或代理的服务器未及时从上游服务器收到请求。 除了上述标准错误代码,还有一些特定的IIS(Internet Information Services)错误,如: - `403 Forbidden`的各种子状态码,表示各种禁止访问的情况。 - `404 Not Found`的子状态码,指出找不到资源的具体原因。 - `405 Method Not Allowed`:请求方法(如PUT、DELETE)不被允许。 - `406 Not Acceptable`:服务器无法提供满足请求首部Accept的响应。 - `410 Gone`:资源已被永久删除。 - `412 Precondition Failed`:请求中的预条件头失败。 - `414 Request-URI Too Long`:请求的URL过长,服务器无法处理。 - `500.100 Incomplete Upload`:ASP中的内部错误,上传数据不完整。 - `500系列`的其他子状态码,通常表示服务器端的特定错误,如配置问题或资源不足等。 了解这些错误代码对于调试Web应用程序、优化网站性能以及解决用户遇到的问题至关重要。它们提供了诊断问题的线索,帮助快速定位并修复网络通信中的障碍。
2023-06-10 上传

// 1、导入模块 const express = require('express'); const mongoose = require('mongoose'); let {log} = console; // 2、创建服务器 const app = express(); app.use(express.static('public'));//设置静态资源文件夹 // 解析post请求 app.use(express.urlencoded({extended:true}),express.json()) // 连接数据库 mongoose.connect('mongodb://localhost/info') .then(()=>log('数据库连接成功')) .catch(()=>log('数据库连接失败')) // 设置集合规则 const infoSchema = new mongoose.Schema({ username:String, password:String }) // 使用集合规则创建集合 const User = mongoose.model('User',infoSchema); // 4、发请求 app.post('/add',(req,res)=>{ // log(req.body); let {username,password} = req.body; // log(username,password) // res.send(JSON.stringify(req.body)) let res1 = User.find({username:username}).then(result=>{ if(result.length==0){ User.create({username:username,password:password}); res.send('true') }else{ res.send('fasle') } }) }) // 3、监听端口 app.listen(3000,()=>log("服务已启动,端口号为3000")) window.onload=function(){ const username = document.getElementsByName('username')[0]; const password = document.getElementsByName('password')[0]; const submit = document.querySelector('.sub'); // console.log(username,password,submit); let userReg = /^[a-zA-Z]{3,10}$/; let pwdReg = /^[0-9]{6,10}$/; submit.onclick = () =>{ if(userReg.test(username.value)&&pwdReg.test(password.value)){ let xhr = new XMLHttpRequest(); xhr.open('post','http://localhost:3000/add',true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.send(`username=${username.value}&password=${password.value}`); // location.href='login.html'; } } }这两段代码应该怎么优化

2023-06-01 上传