422状态代码的一般解释
不幸的是,这个文本块只有英文版本。
The HTTP status code 422 Unprocessable Content is usually returned when the server received the client's request but could not process it due to a semantic error.
This essentially means that the client's request was not understood or accepted by the server because it may have been incomplete or incorrect. A common example of this is when the client attempts to send a form request to the server, but the form field was not filled in correctly.
The server will usually also send back a message in the body of the response giving more details about why the request is unprocessable. It is then up to the client to read and correct this information in order to make a successful request to the server.
HTTP状态代码422的规范
422 Unprocessable Content状态代码意味着服务器理解请求实体的内容类型(因此415(不支持的媒体类型)状态代码是不合适的),并且请求实体的语法是正确的(因此400(坏请求)状态代码是不合适的),但是无法处理包含的指令。例如,如果一个XML请求体包含格式良好(即语法正确),但语义错误的XML指令,就可能出现这种错误情况。
来源/引自: 422 Unprocessable Content HTTP状态代码由11.2的RFC4918部分指定。
如何用PHP抛出一个422状态代码?
要在一个网页上抛出HTTP状态代码422,可以使用PHP函数http_response_code。其语法如下: http_response_code(422) (PHP 5 >= 5.4.0, PHP 7, PHP 8)
测试422 HTTP状态代码
为了能够在客户端显示HTTP状态代码(本例中为422 Unprocessable Content)和其他信息,必须用F12打开开发控制台。然后导航到 "网络 "标签。现在可以打开页面,网站(例如index.php)应该在网络标签中可见。这必须被选中,然后必须选择Herder部分。然后,用户将看到以下结果:
URL: https://http-statuscode.com/errorCodeExample.php?code=422
状况: 422 Unprocessable Content
那些: Network
IP地址: XX.XX.XX.XX
如何为状态代码422创建你自己的错误页面
Apache Webserver
网络服务器 "Apache "是互联网上最常见的网络服务器之一。要在 "Apache "中创建自己的422 Unprocessable Content错误页面,必须在以下文件中做如下修改。
NGINX Webserver
与网络服务器 "Apache "类似,"NGINX "也在互联网上广泛使用。要在 "NGINX "中创建自己的422 Unprocessable Content错误页面,必须在以下文件中做如下修改。
location = /422.html {
root /usr/share/nginx/html;
internal;
}
422状态代码的浏览器兼容性
Chrome | no data |
Edge | no data |
Firefox | no data |
Opera | no data |
Safari | no data |
Chrome Android | no data |
Firefox for Android | no data |
Opera Android | no data |
Safari on iOS | no data |
Internet | no data |
WebView Android | no data |
编程语言中的常量
http.StatusUnprocessableEntity
Response::HTTP_UNPROCESSABLE_ENTITY
http.HTTPStatus.UNPROCESSABLE_ENTITY
:unprocessable_entity