node.js - Request Timeout: GET request timesout when retrieving a file -


i need display pdf file uploaded different server in application. used iframe tag src attribute pointed needed url.

i want allow user print said pdf file can't due cors.

so, decided instead carry out request within server other server has pdf file - idea being fetch pdf other server server , replace src attribute of iframe tag route server handles , responds pdf file, if makes sense

my request looks like:

var options = {     host: host, //the hostname of server contains pdf     path: path, //the path on other server responds pdf     method: 'get',     headers: {} };  http.request(options, function (response) {     var body = '';     response.setencoding('utf8');     response.on('data', function (chunk) {         console.log("gettin data");         body += chunk;     });     response.on('end', function () {         var data = null;         if (body) {             try {                 data = json.parse(body);             }             catch (err) {                 data = body;             }         }          res.sendfile(data);     }); }); 

the problem request times out. should setting headers? url works fine when directly place in address bar of browser - pdf file displayed...

as per documentation can found here, needed end request.

thus adding following solved issue:

var request = http.request(...);  request.end(); 

this ended request , no longer got timeout.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -