簡體   English   中英

嘗試執行從node.js到Django的POST請求

[英]Trying to do a POST request from node.js to Django

我正在嘗試向Django腳本發送一些數據的POST請求。 這只是內部使用的東西,因此安全性不是問題,但它似乎不想打印任何內容。 它打印“ TEST”,所以我知道正確接收了發布請求,但是根據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

(是的,文檔令人困惑,並且沒有很好地顯示類和實例值之間的區別。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM