在axios的post请求中,如果ungzip不起作用,可以尝试以下解决方法:
const axios = require('axios');
const zlib = require('zlib');
axios.interceptors.response.use(function (response) {
const contentEncoding = response.headers['content-encoding'];
if (contentEncoding && contentEncoding.includes('gzip')) {
const gzippedResponse = response.data;
const unzippedResponse = zlib.gunzipSync(gzippedResponse);
response.data = unzippedResponse.toString();
}
return response;
});
axios.post('http://example.com', { data: 'example' })
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});
const axios = require('axios');
axios.post('http://example.com', { data: 'example' }, {
headers: {
'Accept-Encoding': 'gzip',
},
})
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});
以上两种方法都可以解决axios的post请求中ungzip不起作用的问题。根据具体的情况选择适合的方法进行解决。