简体   繁体   中英

Python Post Request Body appears empty in Node server when sent

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"}

我发现我的服务器代码中缺少app.use bodyParser.json() ,这似乎阻止服务器解析不包含文件的多部分表单数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM