Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the status codes of http

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "what are the status codes of http". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Basic introduction

The status code (Status Code) and the reason phrase (Reason Phrase) are used to briefly describe the result of the request. Common ones such as:

200 OK, indicating that the request was successful

404 Not Found indicates that the requested resource was not found.

For status codes such as 200, the first digit of the three digits here usually indicates the category of response (with one or two exceptions), which can be roughly divided into the following categories (see http1.1-RFC6 for the complete table of status codes):

The status code means that the 1xx request is being processed 2xx request successfully processing the 3xx request requires additional operations, for example, an error in redirecting the 4xx client causes the request not to be processed and the 5xx server processing error

(4Jing 5 is often used to screen bugs when throwing pots at each other-_!) the following details of the commonly used status codes and reason phrases

classification

2xx

200 OK

Indicates that the request has been processed normally, which is quite common, so I won't say much about it.

204 NO Content

Indicates that the request was successful, but the response message does not contain the entity body. It is usually used in situations where the client only needs to send information to the server and does not need to accept new information.

Now a very common request type, option, is usually used to pre-request a formal request. This request only needs to confirm whether the subsequent request can be passed, that is, only one result is needed and no other content is returned.

I believe that when we were young, we often took exams. If we take the test questions as an example, then:

Other status codes can be compared to filling in the blanks: the client asks a question (sends a request), and the server gives a detailed answer (returns the physical content).

204 can be understood as a judgment question: the client asks questions (sends the request), and the server gives the judgment, right or wrong (as long as there is a status code in the response header, no physical content is required)

206 Partial Content

Literally: only the portion of the requested resource is returned. In this case, you must mention a request header Range-- in the request of http, which is used to represent the scope request, for example:

'Range':byte=5001-10000 / / represents the 5001-10000 byte portion of the resource to be requested this time

In this case, if the server accepts the scope request and successfully processes it, it returns 206 and returns at the header of the response

'Content-Range':bytes 5001-10000 / / indicates that the entire resource has 10000 bytes. The range returned this time is 5001-10000 bytes.

3xx

301 Moved Permanently

In this case, an address is usually returned in the header field Location of the response, indicating that you want a new address. For example:

The client initiates a request to access site a, and the response is as follows:

301 Moved Permanently... Location: `b.com`. / / the above content indicates: dear, the resource you requested has been transferred. It is recommended that you visit the new address b.com. Please visit the new address directly in the future.

302 Found

Literally: resources have been temporarily redirected. The difference between 301 and 301 is that one is temporary and the other is *: or take the above example, the response is as follows:

302 Found... Location: `b.com`. / / the above content indicates: dear, the resource you requested has been temporarily transferred, and it may also be transferred again later, so it is recommended that you visit the new address b.com this time. In the future, you should visit the original address first. Mm will still be eager to answer any changes for you.

303 See Other

This is similar to 302, but with a slight difference, in addition to prompting the client to request Location, it also requires the GET method to be used when the request is to use Location. I would like to add a historical background:

When the request returns 301 302 303, almost all browsers change the original POST request to the GET request. Although it is stipulated in the FRC1945 and RFC2068 specifications that the client is not allowed to modify the method when redirected.

To put it simply, when dealing with 301 and 302, actual browsers change the original POST request to GET request by default, so in fact, the meaning of 303 is simply to make the semantics clearer. (303 means that the server explicitly tells the client that you want to use the GET method to access location;. If it is 302, it only tells the client to access the location without restricting the method, but in fact the client will also use the GET method to access it. )

304 Not Modified

It literally means that the resource has not changed and the cache can be used directly.

This kind of response is generally accompanied by additional conditions in the GET request, such as if-Match,if-Modified-Since in the request header. (if-Match means to request only resources with special marks, and if-Modified-Since means resources that have not changed after the specified time. Because this article mainly deals with status codes, we do not introduce too many http headers here to briefly explain the meaning of conditional requests.)

In this case, the server will not return the response subject, which means: "this resource has not changed since your last visit, just use your local cache."

(generally speaking, we think that redirection should give a new address for the client to access. 304 if it must be interpreted as redirection, it can only be interpreted as allowing the client to access the cache-_)

307 Temporary Redirect

The purpose of this redirection is to solve a historical background problem just introduced earlier: in 302, the browser will switch to the GET method to request Location by default, but if it is 307, it means that the conversion from POST to GET is strictly restricted, which I rarely encounter in my actual work.

4xx

4xx indicates that there is usually an error on the client side. (this front-end student, take this bug obediently! )

400 Bad Request

(this status code must be familiar to all of you, especially the new beginner ~) 400 has a simple and rude meaning: "Sorry, there is a grammatical error in your request." what exactly is the grammatical error? The answer is-- not necessarily. Generally speaking, there are some hints in the response message, such as:

"Oh, I can't accept what extra headers you have added."

"Oh, your address is not wrong. This uri does not exist."

"Gee, do you have the wrong request method? this uri can only use put instead of post."

Now please feel free to add.

...

401 Unauthorized

Literally: uncertified. Generally, in applications such as backend systems, users will get an authentication information after logging in, and then generate information such as mac, put it in the Authorization field of the request header and send it to the server. If there is a problem with the authentication information or if it has not been sent at all, this status code will appear.

403 Forbidden

This is simple: no access, that is, no access. As for the specific reason why it is forbidden, the server can give it in the physical part of the response content, or it can not be given (yes, my server is so amazing, do whatever you want! )

404 Not Found

It is very common, literally, that the server does not find the requested resource, and experience shows that the general error is that the client's request url is miswritten. (don't ask me how I know)

5xx

5xx indicates that an error occurred on the server side. That's really happy news, boss. Look, it's not my problem! )

500 Internal Server Error

Simple and rude, the server malfunctioned. What? What glitch did you ask me? I don't know, I can only skillfully transfer bug to the server classmate next door.

503 Service Unavailable

The server is temporarily unavailable, it may be maintained or upgraded, but it can't be used anyway.

This is the end of the content of "what are the status codes of http". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report