如何获取NodeJS服务器使用Bottle发送的python中的请求数据

问题描述 投票:0回答:1

如何获取和打印由nodeJS在python中发送的数据?

我在此nodeJs模块中使用ExpressJS

app.use("/py/sendomodel",  function (req, res, next) {
     var oData = {
        "Test":"FirstData"
     }
    var options = {
        method: 'POST',
        data : oData,
        url: 'https://xxx.cfapps.us10.hana.ondemand.com/mprs/omodel',
        headers: {
            'cache-control': 'no-cache',
            /*'Content-Type' :'application/json',*/
            Connection: 'keep-alive',
            'accept-encoding': 'gzip, deflate',
            Host: 'xxxx.cfapps.us10.hana.ondemand.com',
            'Cache-Control': 'no-cache',
            Accept: '*/*',
            'User-Agent': 'PostmanRuntime/7.15.0'
        }
    };
    return request(options, function (error, response,body,data) {
        if (error) throw new Error(error);
    });
});

现在我被困在这里,如何打印发送的数据?这是python模块

from bottle import route, run, post, request, response
@route('/mprs/omodel', method='POST')
def profile():
    #I tried all these without any success , I want to print the oData that I have sent via nodeJs
    #request.body.read().decode('utf8')
    temp = request.body.read()
    #temp = request.json
    #sol = request.forms
    print(temp)   
    #jsonData = json.load(request.body)
    #return jsonData
    return(temp)
python node.js bottle
1个回答
0
投票

您有两件事要看,首先是查询,其次是表单数据。我将两者合并,以防万一。在您的示例中,主体为空。由于没有实际的HTML。

from bottle import route, run, post, request, response

def merge_dicts(*args):
    result = {}
    for dictionary in args:
        result.update(dictionary)
    return result

@route('/mprs/omodel', method='POST')
def profile():
    payload = merge_dicts(dict(request.forms), dict(request.query.decode()))
    print(payload)
© www.soinside.com 2019 - 2024. All rights reserved.