zoukankan      html  css  js  c++  java
  • Atitit web httphandler的实现 java python node.js c# net php 目录 1.1. Java 过滤器 servelet 1 1.2. Python的

    Atitit web  httphandler的实现 java python node.js c# net php

     

    目录

    1.1. Java  过滤器 servelet 1

    1.2. Python的 1

    1.3. php内置Web Server 1

    1.4. Node的 2

    2. 问题 3

     

     

      1. Java  过滤器 servelet

    Atitit 嵌入式 tomcat的使用

     

     

    Node的比较麻烦些。。Php更加简单

     

      1. Python的

    与其它Web后端语言不同,Python语言需要自己编写Web服务器。

    如果你使用一些现有的框架的话,可以省略这一步;

     

    1. 用python建立最简单的web服务器

    利用python自带的包可以建立简单的web服务器。

    格式:

    python -m SimpleHTTPServer port

    例如:

    python -m SimpleHTTPServer 809

    然后在浏览器中输入:

    http://ip:809/路径

    即可访问服务其资源。

    SimpleHTTPServer: 包含执行GET和HEAD请求的SimpleHTTPRequestHandler类。

     

     

      1. php内置Web Server

     

     

    D:wampv2inphpphp5.6.15php.exe -S localhost:8000 -t D:wampv2www

     

    PHP 5.4.0起, CLI SAPI 提供了一个内置的Web服务器。

    这个内置的Web服务器主要用于本地开发使用,不可用于线上产品环境。

    URI请求会被发送到PHP所在的的工作目录(Working Directory)进行处理,除非你使用了-t参数来自定义不同的目录。

    如果请求未指定执行哪个PHP文件,则默认执行目录内的index.php 或者 index.html。如果这两个文件都不存在,服务器会返回404错误。

    当你在命令行启动这个Web Server时,如果指定了一个PHP文件,则这个文件会作为一个“路由”脚本,意味着每次请求都会先执行这个脚本。如果这个脚本返回 FALSE ,那么直接返回请求的文件(例如请求静态文件不作任何处理)。否则会把输出返回到浏览器。

     <?php

    // router.php  D:wampv2inphpphp5.6.15php.exe -S localhost:8000 -t D:dbwebserver D:dbwebserver outer.php

    //   http://localhost:8000/device/get

     

    //echo $_SERVER["REQUEST_URI"];

    if ($_SERVER["REQUEST_URI"]=="/api2")

    {

    header("Access-Control-Allow-Origin: *");

        echo ( file_get_contents('d:dblist.json'));

    return true;

    }

    if (strstr($_SERVER["REQUEST_URI"],"/device/get") )

    {

    header("Access-Control-Allow-Origin: *");

        echo ( file_get_contents('d:dbiot_part.json'));

    return true;

    }

     

     

     

      //  return false;    // 直接返回请求的文件

     

    ?>

     

      1. Node的

     

    var http = require('http');

    var fs = require('fs');

    var url = require('url');

     

    //D:workspace odejs ode.exe D:db odewebserver.js

    // 创建服务器

    port=1314

    http.createServer( function (request, response) {  

     

     

       console.log(request)

    if(request.url==="/api2")

    {

     

     response.writeHead(200, {'Content-Type': 'text/html',"Access-Control-Allow-Origin":"*"});    

             

             // 响应文件内容

             response.write(fs.readFileSync('d:\0db\list.json','utf8'));        

          

             response.end();

    }

     

         

      

    }).listen(port);

     

     

    console.log('Server running at http://localhost:/'+port);

     

     

    1. 问题

    Php的uri会吧querystr也弄到。。所以只好判断包含uri就可

    if (strstr($_SERVER["REQUEST_URI"],"/device/get") )

     

    Atitit 前端测试最简化内嵌web服务器 php 与node.js

     

  • 相关阅读:
    mysql查询缓存
    Mysql 通过binlog日志恢复数据
    mysqlbinlog命令详解
    修改vsftpd默认端口21
    centos 卸载vsftpd方法
    linux挂载u盘和卸载
    Linux下搭建FTP服务器
    fastjson SerializerFeature详解
    Spring JPA使用CriteriaBuilder动态构造查询
    jdk之jps的用法
  • 原文地址:https://www.cnblogs.com/attilax/p/15197042.html
Copyright © 2011-2022 走看看