I am trying to send a post request via Python to my node.js server
My python code looks like:
payload = {
'tableName': 'events',
'whereParams': {
'end_date': ['between', yesterday, today]
}
}
payload = json.dumps(payload)
url = 'http://127.0.0.1:8081/search'
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post(url, headers=headers, data=payload)
jd = r.json()
print jd
My node server file looks like this:
app = express()
app.use busboyBodyParser()
app.use bodyParser.urlencoded({ extended: true })
app.engine 'html', hogan
app.set 'view engine', 'html'
app.post "/search", (req, res, next) ->
queryController.retrieve req, res, next
and my controller in node looks like this:
exports.retrieve = (req, res, next) ->
body = req.body
console.log body
In Node the body is being loged as {}
if I print the payload in python it appears correctly as: {"whereParams": {"end_date": ["between", "2015-09-14 00:00:00", "2015-09-15 00:00:00"]}, "tableName": "events"}
I found out that I was missing
app.use bodyParser.json()
from my server code, which seemed to be preventing the server from parsing multipart form data that did not include a file.