0
var authOptions = {
method: 'POST',
url: url,
data: options.data,
headers: options.headers,
json: true  };

return axios(authOptions)
.then(function(response){
  console.log(response.data);

})
.catch(function(error){
  console.log(error);
});

This is my code snippet. I am trying to make a request to an URL which works fine in my local system. But, when I am running this code inside a windows-server, the JSON returned is incomplete and truncated. It throws an error, unexpected end of JSON. I have tried using the node-rest-client and request as well, but the error persists. any insights into this issue ?

TIA

Nigilan
  • 766
  • 1
  • 6
  • 20
  • Have you been able to log the data at all? I mean sometimes the `data` is completely empty or not json (like HTML from IIS complaining about something). Try setting `json: false` and see what the data contains? – Catalyst Apr 07 '18 at 18:13
  • I am able to log the data sucessfully in both server and client. In server alone, JSON is truncated. – Nigilan Apr 07 '18 at 18:17
  • On the server, you're just running a node process and requesting that data as a user running on the server? No proxy/IIS between you and the node process? – Catalyst Apr 07 '18 at 18:20
  • Yes. Just running the node server. No proxy/IIS . Is that a problem? – Nigilan Apr 07 '18 at 18:22
  • No that's good because then its not some obscure IIS configuration :) How big is the payload? Maybe try using the connection: "keep-alive" header to be sure the server doesn't close the conn early? Also, I think its very unlikely, but if the Content-Length is set wrong things can behave wierdly. – Catalyst Apr 07 '18 at 18:23
  • 1
    Payload is 19kb.Thanks for prompt reply. Will try the keep-alive header :). – Nigilan Apr 07 '18 at 18:29
  • Still no luck. I tried keep-alive as well. I tried as per this one https://medium.com/@ccnokes/one-con-i-discovered-about-axios-recently-is-that-it-doesnt-have-the-best-default-configuration-e6e3a8cba6fa – Nigilan Apr 09 '18 at 05:05
  • Maybe try going around axios? Make the request with superagent or something? If it works then, then the problem is axios for sure. – Catalyst Apr 10 '18 at 02:14
  • I have used node-rest-client and request but not superagent. Will give it a try.. – Nigilan Apr 10 '18 at 05:25
  • another factor could be browser; maybe try another browser if it is IE? – Catalyst Apr 10 '18 at 23:44
  • There is no browser involved. Just checking in the command prompt. – Nigilan Apr 11 '18 at 03:53
  • Could also be related to your body parser. https://github.com/expressjs/body-parser has a limit of 100kb by default. – Catalyst Apr 11 '18 at 04:23
  • But this is for req.body only right ? //Parse incoming request bodies in a middleware before your handlers, available under the req.body property. // – Nigilan Apr 12 '18 at 05:52

1 Answers1

0

Turns out this is not a problem with the nodejs code. Windows network settings have put some restrictions on size while receiving the data. Once those restrctions are removed, it works like charm.

Nigilan
  • 766
  • 1
  • 6
  • 20