试图做一个从node.js到Django的POST请求

我试图做一个POST请求与一些数据到我的Django脚本。 这只是内部使用的东西,所以安全性不是问题,但它似乎不想打印任何东西。 它打印“testing”,所以我知道正在接收发布请求,但根据Django文档, HttpRequest.POST应该打印POST数据字典。

Django的

  @csrf_exempt def botdeposit(request): if request.method == 'GET': print(HttpRequest.GET) return redirect('/') elif request.method == 'POST': print('TEST') print(HttpRequest.POST) return redirect('/') 

的node.js

 var request = require('request'); // Set the headers var headers = { 'User-Agent': 'Super Agent/0.0.1', 'Content-Type': 'application/x-www-form-urlencoded' } // Configure the request var options = { url: 'http://127.0.0.1:8000/test', method: 'POST', headers: headers, form: {'key1': 'xxx', 'key2': 'yyy'} } // Start the request request(options, function (error, response, body) { if (!error && response.statusCode == 200) { // Print out the response body console.log(body) } console.log(body); }) 

request.POST会。 HttpRequest是一个类,你有它的实例。 就像文档说的HttpRequest.method是一件事情,但你写request.method

(是的,文档是混乱的,并没有很好地显示类和实例值之间的差异。)