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

示例代码:

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);
        }
    } );

猜你喜欢

转载自www.cnblogs.com/zifeiy/p/9280094.html