码迷,mamicode.com
首页 > Web开发 > 详细

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

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

标签:get   代码   orm   ranch   err   console   post   host   ext   

示例代码:

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请求样例

标签:get   代码   orm   ranch   err   console   post   host   ext   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!