美文网首页
HTTP 协议

HTTP 协议

作者: michael_jia | 来源:发表于2018-05-15 15:01 被阅读29次

    HTTP(Hypertext Transfer Protocol) 是万维网通信的基石。

    http status code

    Used when the client has closed the request before the server could send a response.
    Used in Nginx logs to indicate when the connection has been closed by client while the server is still processing its request, making server unable to send a status code back.
    Client Error
    The 4XX class of codes indicate you did something wrong. Specifically, there's an error on the client side.

    http server @ github

    a simple zero-configuration command-line http server.
    使用非常简单;

    Transfer-Encoding Header

    Transfer-Encoding: chunked
    开发 PHP 服务时,如果确切地知道返回的内容长度,一定要指定 Content-Length头,否则 Nginx 默认使用 chunked,因为它不知道何时结束,导致即使0字节的返回,网络上也有5个字节的内容传送(不包括 http header 的长度)。
    mdn上的例子很好地诠释了这个原因,如下图:

    mozilla.org上的 chunked 编码示例
    Meta refresh
    <meta http-equiv="refresh" content="5; url=http://example.com/">
    
    • drawbacks:impairs the web browser's "back" button;user dissatisfaction;
    • legitimate uses:Many large websites use it to refresh news or status updates, especially when dependencies on JavaScript and redirect headers are unwanted.
    • You should mention that automatic refresh can be disabled in some browsers.
    Refresh Header
    • 不是 HTTP 标准 Header;
    • Netscape 创建的;
    • 被 W3C 通过 Meta refresh 方式所接纳;
    3 ways of redirection
    • Via 3xx response (in the Location HTTP response header)
    • Via Javascript (or any other client side code) in the response page (e.g. document.location=...)
    • Via "META REFRESH" (<meta http-equiv="Refresh" content="0; url=...">)
    • Refresh Header was invented by Netscape
    URL Redirection
    • URL 跳转
      The simplest way of JavaScript redirect using the onload property of the body tag:
    <body onload="window.location = 'http://example.com/'">
    <!-- Your content here -->
    </body>
    

    HTTP 1.0 vs 1.1

    相关文章

      网友评论

          本文标题:HTTP 协议

          本文链接:https://www.haomeiwen.com/subject/xoftdftx.html