zoukankan      html  css  js  c++  java
  • Atitit recv https req post code 接受https请求// npm install axios// 安装依赖:npm install body-parse

    Atitit recv https req post   code  接受https请求

    原理需要有

    var privateKey = fs.readFileSync('server.key');

    var certificate = fs.readFileSync('server.crt');// jei lyage file releation..can search git sever.crt to

    访问

    //   https://localhost/a1    any http port ...this https not need port,bcs def is 443

    //  npm install  axios

    // 安装依赖:npm install body-parser express --save-dev

    var express = require('express');

    var app_exprs = express();

    var fs = require("fs");

    var bodyParser = require('body-parser');//解析,用req.body获取post参数

    app_exprs.get('/a1', function (req, res) {

        res.end("halo");

    });

    //paresr  can use mlt in same time,auto invoke where client is send..thend set in req.body..

    // parse application/json

    app_exprs.use(bodyParser.json());

    app_exprs.use(bodyParser.raw());

    // auto invoke by parse where client is   'Content-Type: text/plain; charset=utf-8',

    app_exprs.use(bodyParser.text());

    // parse application/x-www-form-urlencoded

    app_exprs.use(bodyParser.urlencoded({extended: false}));

    app_exprs.post("/pst", function (req, res) {

        console.log(JSON.stringify(req.body));

        res.end(" recv json ok..");

    })

    app_exprs.post("/pstxt", function (req, res) {

        console.log((req.body));

        res.end("pstxt ok..");

    })

    var server = app_exprs.listen(888, function () {

        var host = server.address().address

        var port = server.address().port

        console.log("Example app_exprs listening at http://%s:%s", host, port)

    });

    //  npm install express   ...open ide termnal view

    //http://localhost:888/a1

    //http://localhost:888/pst

    //   https://localhost:888/a1

    console.log("boot http finish");

    ///-----------------https

    //   https://localhost/a1    any http port ...this https not need port,bcs def is 443

    https = require("https");

    var privateKey = fs.readFileSync('server.key');

    var certificate = fs.readFileSync('server.crt');// jei lyage file releation..can search git sever.crt to down ...from  prj..

    var credentials = {key: privateKey, cert: certificate};

    var options = {key: privateKey, cert: certificate};

    https.createServer(options, function (req, res) {

        app_exprs.handle(req, res);

    }).listen(443);

    // express.createServer is not a function

    //var app_exprs = express.createServer(credentials);

    //--------------https

    console.log("fff")

  • 相关阅读:
    基于.NET CORE微服务框架 -谈谈Cache中间件和缓存降级
    基于.NET CORE微服务框架 -谈谈surging的服务容错降级
    基于.NET CORE微服务框架 -surging的介绍和简单示例 (开源)
    Git学习记录-基本命令篇
    一个实例搞懂二重指针
    不能将X*类型的值分配到X*类型的实体问题的解决方法
    如何将idea工程打包成jar文件
    windows10环境下安装深度学习环境anaconda+pytorch+CUDA+cuDDN
    指针、地址和引用学习笔记
    几行代码实现cookie的盗取
  • 原文地址:https://www.cnblogs.com/attilax/p/15196803.html
Copyright © 2011-2022 走看看