question

92705102 avatar image
0 Votes"
92705102 asked ·

Can not get parameter from req.body with POST request in Azure NodeJS AppService

Hi

My Windows Azure NodeJS AppService can not get parameter from req.body. I am using Express 4.17 with body-parser. Every time I post a request with body data (example: {"uid":"12345"}) with server-side code

router.post('/abc', function (req, res) {
var uid = req.body.uid;
});

This code worked normally on local but in Windows Azure NodeJS AppService, uid is always Undefined or Null
How can I fix this problem ? Thank you very much.

azure-webappsazure-webapps-content-deploymentazure-webapps-apis
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ryanchill avatar image
0 Votes"
ryanchill answered ·

Hi @92705102,

Since your code is server side, have you tried remote debugging your application? I did come across https://stackoverflow.com/a/13779626/10987310, which contains an example of using body-parser. I've confirmed this does indeed work on a Windows hosted App Service running NodeJS 12LTS.

73557-image.png

I used the following code.

 var express = require('express');
 var bodyParser = require('body-parser')
 var router = express.Router();
    
 var jsonParser = bodyParser.json();
    
 /* GET users listing. */
 router.get('/', function(req, res, next) {
   res.send('respond with a resource');
 });
    
 router.post('/one', jsonParser, function(req, res){
   console.log(JSON.stringify(req.body));
   res.send(req.body.name);
 });
    
 module.exports = router;

Regards,
Ryan



image.png (42.8 KiB)
· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

It worked ! Thank you very much

0 Votes 0 ·