0
我需要顯示上傳到我的應用程序中不同服務器的PDF文件。我使用了iframe
標籤,其src屬性指向了所需的URL。請求超時:檢索文件時GET請求超時
我也想讓用戶打印上述PDF文件,但我不能因爲CORS。
因此,我決定改爲從我的服務器執行GET請求到另一個具有PDF文件的服務器 - 這個想法是我從其他服務器獲取PDF到我的服務器,然後替換src
屬性在iframe
標籤與我的服務器處理,並與PDF文件的響應,如果是有道理的
我的GET請求看起來像一個路線:
var options = {
host: host, //the hostname of the server that contains the PDF
path: path, //the path on the other server that responds with the 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);
});
});
的問題是,該請求只是超時。我應該設置一些標題嗎?當我直接將它放在瀏覽器的地址欄中時,URL正常工作 - 即顯示PDF文件...
想通了。在調用http請求後,我沒有調用request.end()... – callmekatootie
要麼回答你自己的問題,要麼刪除它。 – Gntem