what is the problem i don't know please help to solve this. when i post data then below error shows on terminal. Attach is the code also.
Error: Argument error, options.body. at Request.init (/usr/lib/nodejs/request/index.js:351:13) at new Request (/usr/lib/nodejs/request/index.js:124:8) at Object.request (/usr/lib/nodejs/request/index.js:1279:11) at Request._callback (/var/www/html/nodeproject/helloworld/controllers/login.js:68:11) at Request.self.callback (/usr/lib/nodejs/request/index.js:148:22) at Request.EventEmitter.emit (events.js:98:17) at Request.<anonymous> (/usr/lib/nodejs/request/index.js:896:14) at Request.EventEmitter.emit (events.js:117:20) at IncomingMessage.<anonymous> (/usr/lib/nodejs/request/index.js:847:12) at IncomingMessage.EventEmitter.emit (events.js:117:20)
below is my code here am posting data using json.
module.exports.controller = function(BASE) { var token_array = new Array(); BASE.APP.get('/login', function(req, res) { res.render('pages/login'); //res.sendFile(__dirname + '/login.html'); }); BASE.APP.post("/login", BASE.urlEncodedParser, function(req, response) { var devicetoken = req.usersession.devicetoken; var body = req.body; req.usersession.username = body.username; console.log(req.body); var userData={ "deviceToken" : devicetoken, "password" : body.pwd, "username" : body.username }; var digest = BASE.utils.hmac("sha1", "A12AA418-1F28-4464-8B67-29CBD02BC45C-F048B14F-F3E3-4F97-A522-F2275A364A0E", JSON.stringify(userData)); var postData = { "deviceToken" : devicetoken, "password" : body.pwd, "username" : body.username, "digest" : digest }; var sPostData = BASE.utils.base64encode(BASE.utils.base64encode(JSON.stringify(postData))); BASE.request({ url: "http://example.com/authenticate/", method: "POST", headers: { "content-type": "application/json", }, body: sPostData }, function(err,result,body){ //console.log(JSON.stringify(postData)); var body = JSON.parse(body); req.usersession.token = body.token; /*********************************has login permission***************************************/ var loginData={ "permission" : '08008749-F3A5-480B-A2B2-C21CEFED70F4', "token" : req.usersession.token }; var logindigest = BASE.utils.hmac("sha1", "A12AA418-1F28-4464-8B67-29CBD02BC45C-F048B14F-F3E3-4F97-A522-F2275A364A0E", JSON.stringify(loginData)); var loginpostData = { "permission" : '08008749-F3A5-480B-A2B2-C21CEFED70F4', "token" : req.usersession.token, "digest" : logindigest }; BASE.request({ url : "http://example.com/hasPermission/", method :"POST", headers : { "content-type": "application/json", }, body :loginpostData }, function (err,result1,body) { console.log(body); }); //response.redirect(301, '/contacts'); }); }); }
i am using same type code of another file what it should not give any error but this file show me
Try adding json: true
in your request options.
For example:
BASE.request({ url : "http://example.com/hasPermission/", method :"POST", headers : { "content-type": "application/json", }, body: loginpostData, json: true },
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With