使用Axios POST时的不确定结果

时间:2019-11-13 08:48:11

标签: node.js api post axios adonis.js

我尝试在axios中使用Post方法发送一些数据,但是我的代码结果仅未定义。 这是我使用axios发布http请求的代码:

const Axios = use('axios');
const Env = use('Env');
const querystring = require('querystring');

class getTrackingData({ response }) {

    const tracking = await Axios.post(Env.get('APP_ENDPOINT') + '/waybill',
            {
                data: querystring.stringify({
                    waybill : 'SOCAG00183235715', courier : 'jne'
                })
            },
            {
                headers: {
                    'key':Env.get('APP_KEY'),
                    'content-type': "application/x-www-form-urlencoded"
                }
            }).then(function(response) {
                console.log(response.data);
                //return response.data;
            });
        return tracking;
}
}

此代码有什么问题?

2 个答案:

答案 0 :(得分:0)

尝试一下

'content-type': "application/application.json"

有关详情example

更新

请在标题中添加

headers: {
   'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}

Refrence Link

答案 1 :(得分:0)

我不知道,但是我认为这是因为发送的格式数据不可读,所以我试图更改发送的数据格式,如下所示:

.m

这对我有用!