zoukankan      html  css  js  c++  java
  • PHP中的http协议

    http协议基本组成


    报文:用于Http协议交互的信息

    请求行:包括请求的方法,URL和HTTP协议版本

    状态行:包括响应结果的状态码,状态描述和Http版本

    首部字段:包括请求和响应的各种条件和属性值(键值对)


     下面通过一个实例来进行演示:

    在localhost目录下建立index.php

    1
    2
    3
    <?php
        echo "Http demo";
    ?>

      接下来,在浏览器中打开localhost



    一共三部分信息。

    telnet模拟Http请求

    1. cmd下->telnet主机地址 80

    2. 按下快捷键:ctrl+"]" 再按下回车键 打开回显功能

    3. 发送请求报文

    'telnet' 不是内部或外部命令,也不是可运行的程序,解决方法:控制面板 -> 程序 -> 打开或关闭Windows功能 -> 勾选Telnet客户端 -> 确定。Win + R打开cmd窗口,输入以下命令。

    C:UsersThinkPad>telnet 127.0.0.1 80

    接着回车后按下Ctrl + ] 打开回显功能,然后再按回车键。


    输入请求行后回车。


     分析内容含义:

    GET(请求方法) /index.php(请求URL) HTTP/1.1(http协议版本)----->请求行
    Host:localhost(请求首部)
    (空行)
    响应内容:
    HTTP/1.1 200(响应结果状态码) OK(状态描述)
    Date: Sun, 12 Mar 2017 13:25:07 GMT
    Server: Apache/2.4.4 (Win32) OpenSSL/1.0.1e PHP/5.5.3
    X-Powered-By: PHP/5.5.3
    Content-Length: 14
    Content-Type: text/html
    (空行)
    锘縣ttp demo

     修改index.php内容如下:

    1
    2
    3
    4
    5
    <?php
        //echo "Http demo";
        $str = implode($_POST," ");
        echo $str;
    ?>

      在环境变量的系统变量path属性中添加C:WindowsSystem32;即可满足cmd粘贴功能。

    下面演示POST请求:


    POST /index.php HTTP/1.1(请求行)

    HOST:localhost
    Content-type:application/x-www-form-urlencoded(首部)
    content-length:20(下面是空格)

    act=query&name=ghostHTTP/1.1 200 OK
    Date: Sun, 12 Mar 2017 14:10:51 GMT
    Server: Apache/2.4.4 (Win32) OpenSSL/1.0.1e PHP/5.5.3
    X-Powered-By: PHP/5.5.3
    Content-Length: 16
    Content-Type: text/html

    文章来源:David-Zhong  连接:https://www.cnblogs.com/ioveNature/p/6538516.html

  • 相关阅读:
    JavaScript模态对话框类
    事件模块的演变(1)
    html5中可通过document.head获取head元素
    How to search for just a specific file type in Visual Studio code?
    What do 'lazy' and 'greedy' mean in the context of regular expressions?
    正则非获取匹配 Lookahead and Lookbehind ZeroLength Assertions
    regex length 正则长度问题
    Inversion of Control vs Dependency Injection
    How to return View with QueryString in ASP.NET MVC 2?
    今天才发现Google Reader
  • 原文地址:https://www.cnblogs.com/Bhi9712/p/9834679.html
Copyright © 2011-2022 走看看