zoukankan      html  css  js  c++  java
  • node 请求接口



    1、app.js

    var express = require('express')
    const bodyParser = require('body-parser')
    const cookieParser = require('cookie-parser');





    var app = express();
    app.use(bodyParser())
    app.use(cookieParser())



    app.get('/', function(req, res){
        console.log(req.query)
        res.json({success:100})
    })
    app.post('/', function(req, res){
        console.log(req.body)
        res.json({success:2000})
    })




    app.listen(3000)

    2、client.js

    var express = require('express')
    var app = express();
    var Client = require('node-rest-client').Client;
    var client = new Client();

    app.get('/', function(req, res){
        var args = {
            parameters: { arg1: "hello", arg2: "world" },
            headers: { "test-header": "client-api" }
        };
        client.get("http://localhost:3000",args, function (data, response) {
            console.log(data);
           // console.log(response);
        });

    })
    app.get('/abc', function(req, res){
        var args = {
            data: { test: "hello" ,user:11111},
            headers: { "Content-Type": "application/json" }
        };
        client.post("http://localhost:3000",args, function (data, response) {
            console.log(data);
            res.send(data)
           // console.log(response);
        });

    })

    app.listen(8888)

    3、分别启动app.js 和 client.js

    4、在网站出入locahost:8888

  • 相关阅读:
    迷宫寻找路径数
    136. 只出现一次的数字
    48. 旋转图像
    283. 移动零
    面试题 01.06. 字符串压缩
    位运算符
    367. 有效的完全平方数
    868. 二进制间距
    SpringAOP表达式
    Mybatis常见错误及纠错
  • 原文地址:https://www.cnblogs.com/zhangshuda/p/7640341.html
Copyright © 2011-2022 走看看