Front end learning (4) -- response line, response head, response body

Tom conton 2020-11-13 02:05:24
end learning response line response

One . Corresponding line --- The status code of the response

HTTP Status code classification

HTTP The status code consists of three decimal digits , The first decimal number defines the type of status code , The last two numbers have no role in classification .HTTP Status codes are divided into 5 Types :

HTTP Status code classification
classification Classification description
1** Information , The server receives the request , Requester is required to continue
2** success , Operation received and processed successfully
3** Redirect , Further action is required to complete the request
4** Client error , The request contains a syntax error or could not be completed
5** Server error , The server encountered an error while processing the request


HTTP Status code list :

HTTP Status code list
Status code English name of status code Chinese description
100 Continue continue . client Should continue its request
101 Switching Protocols Handover protocol . Server switches protocol according to client's request . Can only switch to a more advanced protocol , for example , Switch to HTTP New version agreement for
200 OK The request is successful . Commonly used in GET And POST request
201 Created Created . Successfully requested and created a new resource
202 Accepted Accepted . Request accepted , But not finished
203 Non-Authoritative Information Unauthorized information . The request is successful . But returned meta The information is not on the original server , It's a copy
204 No Content There is no content . Server processed successfully , But no content returned . Without updating the page , Ensures that the browser continues to display the current document
205 Reset Content Reset Content . Server processed successfully , user terminal ( for example : browser ) Document view should be reset . You can use this return code to clear the form field of the browser
206 Partial Content Part content . Server successfully processed part GET request
300 Multiple Choices Multiple choice . The requested resource can include multiple locations , Accordingly, a list of resource characteristics and addresses can be returned for the user terminal ( for example : browser ) choice
301 Moved Permanently A permanent move . The requested resource has been permanently moved to the new URI, The return information will include the new URI, Browser will be automatically directed to new URI. Any new request in the future should use the new URI Instead of
302 Found Temporary movement . And 301 similar . But resources are only temporarily moved . The client should continue to use the original URI
303 See Other View other addresses . And 301 similar . Use GET and POST Request to view
304 Not Modified not changed . The requested resource has not been modified , When the server returns this status code , No resources will be returned . Clients usually cache accessed resources , Indicate by providing a header that the client wants to return only resources modified after a specified date
305 Use Proxy Using agents . The requested resource must be accessed through a proxy
306 Unused Abandoned HTTP Status code
307 Temporary Redirect Temporary redirection . And 302 similar . Use GET request redirections
400 Bad Request Syntax error in client request , Server does not understand
401 Unauthorized Request for user authentication
402 Payment Required Retain , Future use
403 Forbidden The server understands the request from the requesting client , But refused to execute the request
404 Not Found The server could not find the resource at the request of the client ( Webpage ). By this code , Website designer can set " The resource you requested could not be found " Personal page of
405 Method Not Allowed Method in client request is forbidden
406 Not Acceptable The server could not complete the request based on the content characteristics requested by the client
407 Proxy Authentication Required Request for proxy authentication , And 401 similar , But the requester should use a proxy to authorize
408 Request Time-out Server waits too long for client to send request , Overtime
409 Conflict Server completes client's PUT This code may be returned on request , A conflict occurred while the server was processing the request
410 Gone The resource requested by the client no longer exists .410 differ 404, If the resource has been permanently deleted before, it can be used 410 Code , Website designers can use 301 Code specifies the new location of the resource
411 Length Required The server cannot process the client sent without band Content-Length Request information for
412 Precondition Failed Client request information precondition error
413 Request Entity Too Large Because the requested entity is too large , Server cannot process , So reject the request . To prevent continuous requests from clients , The server may close the connection . If it's just the server that can't handle it temporarily , Will contain a Retry-After Response information for
414 Request-URI Too Large Requested URI Too long (URI Usually web address ), Server cannot process
415 Unsupported Media Type The server cannot process the media format that came with the request
416 Requested range not satisfiable Invalid range requested by client
417 Expectation Failed Server can't satisfy Expect Request header information for
500 Internal Server Error Server internal error , Unable to complete request
501 Not Implemented The server does not support the requested feature , Unable to complete request
502 Bad Gateway When a server working as a gateway or proxy attempts to execute a request , An invalid response was received from the remote server
503 Service Unavailable Due to overload or system maintenance , The server is temporarily unable to process the client's request . The length of the delay can be included in the server's Retry-After In header information
504 Gateway Time-out Server acting as gateway or proxy , Request not obtained from remote server in time
505 HTTP Version not supported The server does not support the requested HTTP Version of protocol , Unable to complete processing


Two . http Response header information for


What request methods does the server support ( Such as GET、POST etc. ).


Document coding (Encode) Method . It can only be obtained after decoding Content-Type Content type specified by header . utilize gzip Compressing documents can significantly reduce HTML Download time of document .Java Of GZIPOutputStream It can be carried out easily gzip Compress , But only Unix Upper Netscape and Windows Upper IE 4、IE 5 To support it . therefore ,Servlet Should be checked by Accept-Encoding head ( namely request.getHeader("Accept-Encoding")) Check whether the browser supports gzip, For support gzip Browser return via gzip Compression of the HTML page , Return to normal page for other browsers .


Indicates content length . Only if the browser is persistent HTTP This data is only needed when connecting . If you want to take advantage of persistent connections , Output documents can be written to ByteArrayOutputStream, View its size when finished , Then put the value in the Content-Length head , Finally through byteArrayStream.writeTo(response.getOutputStream() send content .


Indicates what subsequent documents belong to MIME type .Servlet The default is text/plain, But you usually need to explicitly specify as text/html. Due to frequent setting Content-Type, therefore HttpServletResponse Provides a dedicated approach setContentType.


Current GMT Time . You can use it. setDateHeader To set this header to avoid the trouble of converting the time format .


When should the document be considered out of date , So you don't cache it anymore ?


Last change time of document . Customers can use If-Modified-Since Request header provides a date , The request will be treated as a condition GET, Only documents with changes later than the specified time will be returned , Otherwise, return one 304(Not Modified) state .Last-Modified Also available setDateHeader Method to set .


Indicates where the customer should go to extract the document .Location Usually not set directly , But through HttpServletResponse Of sendRedirect Method , This method also sets the status code to 302.


Indicates how long the browser should refresh the document , In seconds . In addition to refreshing the current document , You can also pass setHeader("Refresh", "5; URL=http://host/path") Let browser read the specified page .
Note that this function is usually set by HTML page HEAD District <META HTTP-EQUIV="Refresh" CONTENT="5;URL=http://host/path"> Realization , This is because , Automatic refresh or redirection is not available for those CGI or Servlet Of HTML The writer is very important . however , about Servlet Come on , Set up directly Refresh More convenient head .

Be careful Refresh The meaning is "N Refresh this page or visit the specified page in seconds ", instead of " every other N Seconds to refresh this page or visit the specified page ". therefore , Continuous refresh requires one at a time Refresh head , And send 204 The status code prevents the browser from continuing to refresh , No matter it's used Refresh Head or <META HTTP-EQUIV="Refresh" ...>.

Be careful Refresh Head doesn't belong to HTTP 1.1 Part of the formal specification , It's an extension , but Netscape and IE All support it .


Server name .Servlet Generally, this value is not set , But by the Web Server settings .


Set the associated Cookie.Servlet Should not be used response.setHeader("Set-Cookie", ...), Instead, use HttpServletResponse Special methods provided addCookie. See below about Cookie Discussion of settings .


The customer should be Authorization What type of authorization information is provided in the header ? Include in 401(Unauthorized) This header is required in the response of the status line . for example ,response.setHeader("WWW-Authenticate", "BASIC realm=\"executives\"").
Be careful Servlet Generally, this aspect will not be dealt with , Rather let Web Server specific mechanism to control access to password protected pages ( for example .htaccess).


本文为[Tom conton]所创,转载请带上原文链接,感谢

  1. css单位
  2. CSS unit
  3. 前端验证集合
  4. Front end validation collection
  5. Lesson 27: using time measuring tools to explore available spare time
  6. CSS 单位
  7. CSS unit
  8. 前端工具集合
  9. Front end Tools Collection
  10. Introduction to HTTP message format
  11. Introduction to new features of HTML5
  12. Common instructions for Vue
  13. Introduction of bootstrap Blazer component library
  14. HTML5 速览
  15. HTML5 quick view
  16. HTML表格自动排序
  17. For less than $1700, create a private cloud with openstack
  18. Basic learning of JavaScript (1)
  19. 前端编程之路一一HTML标签分类
  20. Front end Programming: HTML tag classification
  21. ColSpan and rowspan merging cells of HTML form elements
  22. JavaScript 日期时间格式化
  23. JavaScript date time formatting
  24. Classification of front end interview questions - html2
  25. CSS block elements
  26. HTML5 form detailed tutorial
  27. HTML5 form detailed tutorial
  28. HTML5新增的元素表
  29. New element table in HTML5
  30. 3D轮播插件vue-carousel-3d非官方最全文档
  31. 3D carousel plug-in vue-carousel-3d
  32. Uniapp (Vue general) integrates Tencent location service SDK -- multi platform small program general
  33. Slowhttptest slow attack tool use details
  34. HTML summary (2)
  35. Overview of CSS3
  36. Front end abnormal monitoring system
  37. 免费网站部署和免费数据库Serverless云存储资源汇总整理
  38. Free website deployment and collection of free database serverless cloud storage resources
  39. Vux form -- a form solution of base vux
  40. 可以直接用于HTML中的特殊字符表 unicode字符集
  41. Can be directly used in HTML special character table Unicode character set
  42. Detailed explanation of HTTP protocol
  43. HTTP request header and request response header
  44. CSS background深度解析
  45. Python web/HTML GUI
  46. Front end standard 2: HTML you know and don't know
  47. Some HTML tags
  48. HTML标签之table
  49. Table of HTML tag
  50. DataTables of jQuery plug-in
  51. Unity calls Google's free translation API (HTTPS interface). Young people don't speak martial arts. How can they speak in multiple languages
  52. Linux entry most commonly used commands, do not learn a bunch of useless commands
  53. Piziheng embedded: a list of common short-range wireless communication protocols (Wi Fi / Bluetooth / ZigBee / thread...)
  54. Naming rules for the front end team of ladder
  55. HTML logo related symbols
  56. Node . JS: development resources and technology stack arrangement
  57. Unity calls Google's free translation API (HTTPS interface). Young people don't speak martial arts. How can they speak in multiple languages
  58. Straighten out JavaScript (18) - statements and operators
  59. Employment information statistics network (interface document)
  60. css selector