I am fetching a web page with axios, but the content-type of the response is ISO-8859-1, and the result given by axios seems like it parses it as UTF-8 and the result has corrupt characters.
I tried to convert the result encoding but nothing works, and I think it does not because of this
For example in the got library I can set encoding to null and overcome the problem, but I would like to ask you what can I do with axios to disable the auto-encoding or change it?
In node. js, you can use the querystring module as follows: const querystring = require('querystring'); axios. post('http://something.com/', querystring.
Making a POST request in Axios requires two parameters: the URI of the service endpoint and an object that contains the properties you wish to send to the server. For a simple Axios POST request, the object must have a url property. If no method is provided, GET will be used as the default value.
My approach was this:
responseType
and responseEncoding
set as belowconst response = await axios.request({
method: 'GET',
url: 'https://www.example.com',
responseType: 'arraybuffer',
responseEncoding: 'binary'
});
reponse.data
to the desired formatlet html = iso88592.decode(response.data.toString('binary'));
Note: In my case, I needed to decode it using this package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With