zoukankan      html  css  js  c++  java
  • HTTP 协议 get post 请求方式

     

    // 创建服务器模块
    const http = require('http');
    // app 对象就是网站服务器对象 
    const app = http.createServer();
    // 当有请求的时候 
    app.on('request', (req, res) => {
        // 获取请求方式
        // req.method
        // console.log(req.method);

        // 获取请求地址
        // console.log(req.url);

        // 获取请求报文信息
        // req.headers
        // console.log(req.headers['accept']);


        res.writeHead(200, {
            'content-type': 'text/plain;charset=utf8'
        });

        if (req.url == '/index' || req.url == '/') {
            res.end('<h2>welcome to homepage,欢迎来到首页</h2>');
        } else if (req.url == '/list') {
            res.end('welcome listpage');
        } else {
            res.end('Not Found');
        }

        if (req.method == 'POST') {
            res.end('POST');
        } else if (req.method == 'GET') {
            res.end('GET');
        }


        // res.end('<h2>hello 222 user</h2>');
    });
    // 监听端口
    app.listen(3000);
    console.log('网站服务器启动成功...');

  • 相关阅读:
    Phpstorm+Xdebug配置
    ThinkPHP5.0---URL访问
    Thinkphp5创建控制器
    ThinkPHP5.0的安装
    网页动态背景——随鼠标变换的动态线条
    git SSH
    [go] 循环与函数
    svg make a face
    Hello Vizhub
    Beetlsql自定义生成entity,mapper,md代码
  • 原文地址:https://www.cnblogs.com/ericblog1992/p/13084747.html
Copyright © 2011-2022 走看看