无法显示来自 Axios 的响应

时间:2021-02-04 11:55:53

标签: javascript axios

我是使用 Axios 的新手,并且正在努力显示响应函数中的任何内容。我主要有兴趣至少看到响应状态。我能看到的唯一输出是返回 4xx 代码时,但调用成功时什么也没有。

以下是我的代码,任何帮助将不胜感激:

  setServiceGroupPromise(){

    //Read data from ./data/sourcingRules.txt

        let filePath = './data/sourcingRules.txt';
var fileData = fs.readFileSync(filePath, 'utf8');

console.log(fileData);
let postURL = `${siteConfig}`;

    const config = {
        method: 'post',
        url: postURL,
        params: {
            'apiKey': process.env.SHIPPING_SERVICE_API_KEY
        },

        headers: {
            'content-type': 'application/xml',            
        },
        data: fileData
        };
        console.log(`Post request going to: ${postURL}`);

      axios(config)
            .then(function (response) {
                    console.log(response.data);
                console.log(response.status);    
                
        })
            .catch(function (error) {
                console.log('The following error occurred : ' + error.message);      
             });
          
}

1 个答案:

答案 0 :(得分:0)

如果您没有看到 console.log(response.data) 中的任何内容,请尝试记录类似 console.log({response})console.log('show me something', response.data)

相关问题