NodeJs request response body is empty

736 views Asked by At

Don't understand why the response body of the following request is empty:

request:

req.headers['User-Agent'] = 'request';
req.headers['Accept'] = 'text/html';

const options = {
    url: config.prodURL,
    headers: req.headers,
    qs: req.query,
    method: req.method
};
request(options, (err, resp, body) => {

       console.log(resp);
});

I'm expecting HTML in this response, but for some reason, when I look at resp it displays body: ''

Part of the resp contains the href url and if I use this in any client, it displays the HTML code.

What is wrong with this config?

update

Here's the data with the exception of hrefas I cannot share this URL. err is null, here are the rest of the values:

{ url: 'http://my.url/',
  headers:
   { 'user-agent': 'PostmanRuntime/7.15.2',
     accept: '*/*',
     'cache-control': 'no-cache',
     'postman-token': '8c208831-580b-4460-b3e0-046d85789658',
     host: 'localhost:8001',
     'accept-encoding': 'gzip, deflate',
     connection: 'keep-alive',
     'User-Agent': 'request',
     Accept: 'text/html' },
  qs: { query-params... },
  method: 'GET' 
}

I believe it might be related to the response headers, the URL requested doesn't return any, so does requestJs require a content-type to be able to parse the body?

0

There are 0 answers