When request sends a json body, it's like this
const request = require('request')
request.post('https://flaviocopes.com/todos', {
json: {
todo: 'Buy the milk'
}
}, (error, res, body) => {
console.log(body)
})
When i want to use requestretry, it has the same field json, but set to true or false, so how can i retry on send request with json body ?
var request = require('requestretry');
request({
url: 'https://api.domain.com/v1/a/b',
json: true,
// The below parameters are specific to request-retry
maxAttempts: 5, // (default) try 5 times
retryDelay: 5000, // (default) wait for 5s before trying again
retryStrategy: request.RetryStrategies.HTTPOrNetworkError // (default) retry on 5xx or network errors
}, function(err, response, body){
// this callback will only be called when the request succeeded or after maxAttempts or on error
if (response) {
console.log('The number of request attempts: ' + response.attempts);
}
});
From the documentation, Request-retry is a drop-in replacement for request but adds two new options maxAttempts and retryDelay. . You should be able to pass the JSON in json: { ... }
like you would with request
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.