【发布时间】:2015-04-21 01:52:10
【问题描述】:
我正在尝试向我的 Django 脚本发出带有一些数据的 POST 请求。它只是供内部使用的东西,所以安全性不是问题,但它似乎不想打印任何东西。它打印“TEST”,所以我知道 post 请求被正确接收,但根据 Django 文档,HttpRequest.POST 应该打印 POST 数据的字典。
姜戈
@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);
})
【问题讨论】:
标签: javascript python django node.js