android - Do i still use req.body for json, from Mobile to node.js? -
do still use req.body if let say, android or ios sending json object node.js server?
for example, code
router.post('/submit', function(req, res, next) { var movie = new movie(); movie.name = req.body.name; movie.save(function(err) { if (err) return next(err); return res.json(movie); }); });
yes, that's correct.
provided used key value pairs or write output stream.
//set httpurlconnection url url = new url("http://url.com"); httpurlconnection conn = (httpurlconnection) url.openconnection(); conn.setrequestmethod("post"); conn.setdoinput(true); conn.setdooutput(true); outputstream os = conn.getoutputstream(); bufferedwriter writer = new bufferedwriter(new outputstreamwriter(os, "utf-8")); //this post data writer.write("name=" + moviename); writer.flush(); writer.close(); os.close(); conn.connect();
you can send json using:
writer.write("movie=" + jsondata.tostring());
Comments
Post a Comment