得到 npm 模块:如何重试 POST 请求?

got npm module : How to retry for POST requests?

以下示例适用于 GET 请求,但不适用于 POST 请求。我如何让它适用于 POST?

https://www.npmjs.com/package/got#retry

const got = require('got')
const retry = {
  retry: {
    retries: 3
  }
}
got('http://localhost:3000/retry', retry).then(({ body }) => {
  console.log(body);
}).catch((err) => {
  console.log(err);
});

重试次数为 3 的示例 POST 请求。如果要禁用重试,请将重试次数设置为 0。

const got = require('got');
start()
async function start() {
 var response = await request()
 console.log(response);  
}

async function request() {
try {
    const response = await got.post('https://example.com', { retry: { limit: 3, methods: ["GET", "POST"] } });
    return response.body
 } catch (error) {
    console.log(error.response.body);   
    return error
 }
}

对于POST添加方法如下图,对于POST默认got不支持重试

got.post('https://example.com', { retry: { limit: 1, methods: ["GET", "POST"] } });