I've looked at various posts on this topic but am still running into an error with this.
Python code:
import requests
import json
url = 'http://127.0.0.1:8080/ay'
payload = {'some': 'data'}
r = requests.post(url, data=payload)
print r.text
print r.status_code
Node.js code:
var app = express();
app.use(bodyparser.urlencoded({
extended: true
}));
app.use(bodyparser.json());
app.post('/ay', function(req, res){
console.log(req.body);
res.send('done');
});
So I've looked at my req and even req.body but req.body returns undefined so I think it's with json=payload but I've also tried params=payload and data=json.dumps(payload)
Edit: I forgot to include bodyparser and urlencoded. I edited my code to show the changes.
body-parsermodule's JSON middleware).body-parserto parse the json request?var bodyParser = require('body-parser'); app.use(bodyParser.json());