【发布时间】:2019-02-14 21:17:21
【问题描述】:
我有一个 JSON 对象,我希望使用服务器的 API 密钥将其发送到服务器。我希望重试次数为 3,以便在之前的调用失败时重试发送数据。
我不确定是使用“axios-retry”还是“retry-axios”。 如何在标头中配置 Content-Type,在哪里添加 API 密钥和要发送的数据。我现在的代码如下所示:
const axiosRetry = require('axios-retry');
axiosRetry(axios, { retries: 3 });
var data = { /*----My JSON Object----*/ };
axios.post('my url', data, {
headers: {
'Authorization': 'API_Key',
'Content-Type': 'application/json'
}
})
.then(function(response){
console.log(response);
})
.catch(function(error){
console.log(error);
});
【问题讨论】: