This article mainly introduces the use of superagent to simulate GET/POST requests in Node.js. It has certain reference value. Now I share it with you. Friends in need can refer to it
Sample code:
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); } } );
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
js gets the distance between the page element and the top of the browser workspace
react request.js function encapsulation
The above is the detailed content of Node.js uses superagent to simulate GET/POST requests. For more information, please follow other related articles on the PHP Chinese website!