Michael Joseph Aubry
Michael Joseph Aubry

Reputation: 13482

Node.js request to xml document not receiving properly encoded format?

I am not entirely sure why, but I am receiving data that looks like n�F����S� from a call to an rss feed that is formatted in xml.

    exports.search = function(req, res) {
        request.get('https://secret.co/usearch/'+req.params.id+'/?rss=1', function (error, response, body) {
          console.log(body);
          if (!error && response.statusCode == 200) {
            parseString(body, function (err, result) {
              res.json(result);
            });
          }
        });
    };

Just on a particular url, I am wondering how I can solve this and get proper xml?

Upvotes: 1

Views: 49

Answers (1)

saintedlama
saintedlama

Reputation: 6898

The URL in question delivers content gzip encoded. Adding the option gzip : true to the request call will fix the problem:

exports.search = function(req, res) {
    request({ method : 'GET', url: 'https://kat.cr/usearch/scarface/?rss=1', gzip: true }, function(error, response, body) {
      console.log(body);
      if (!error && response.statusCode == 200) {
        parseString(body, function (err, result) {
          res.json(result);
        });
      }
    });
};

Upvotes: 1

Related Questions