首页 > Web开发 > 详细

Node.js使用superagent模拟GET/POST请求样例

时间:2018-07-08 16:21:45      阅读:428      评论:0      收藏:0      [点我收藏+]

示例代码:

var superagent = require(‘superagent‘);

superagent.get("http://localhost:8091/user/all?reqUsername=admin&reqPasswd=654321")
    .end( (err, res)=> {
        if (err) {
            console.log("出错:" + err);
        } else {
            console.log(res.text);
        }
    } );

// user add
var url = "http://localhost:8091/user/update"
superagent.post(url)
    .type("form")
    .send({
        id: ‘5‘,
        fullname: ‘刘德华‘,
        username: ‘8839001‘,
        passwd: ‘111111‘,
        branch: ‘123001‘,
        rights: ‘3‘,
        memo: ‘依然范特西‘,
        reqUsername: ‘admin‘,
        reqPasswd: ‘654321‘
    })
    .end( (err, res)=> {
        if (err) {
            console.log("出错:" + err);
        } else {
            console.log(res.text);
        }
    } );

Node.js使用superagent模拟GET/POST请求样例

原文:https://www.cnblogs.com/zifeiy/p/9280094.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!