【发布时间】:2020-07-08 15:02:27
【问题描述】:
有人知道如何读取或访问 HTTP 响应的附件吗?
我的意思是,服务器响应是:
HTTP/1.1 200 OK
Server: something
Date: Fri, 01 May 2015 10:22:29 GMT
Content-Type: application/pdf
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Language, Cookie
X-Frame-Options: SAMEORIGIN
Content-Language: en
Content-Disposition: attachment; filename=mybill-234324.pdf
Set-Cookie: s=xxxxx; expires=Fri, 15-May-2015 10:22:29 GMT; httponly; Max-Age=1209600; Path=/; secure
Strict-Transport-Security: max-age=15552000
但是这个mybill-234324.pdf文件内容在哪里???
我的代码:
var req = https.request({
method: 'GET',
host: 'thehost.ext',
path: '/account/bills/' + number + '/',
headers: {
'Cookie': 's=supercryptedhash;',
'Accept-Language': 'en-US,en'
}
}, function(res) {
// ????
});
req.on('error', function(err) {
console.error('Request Error', err);
});
req.end();
【问题讨论】:
-
请提供代码示例
-
在问题编辑中提供。
-
Answer use 'request' module 我无法安装,我需要一个基于 'http' 或 'https' 节点原生模块的解决方案。
-
您的响应处理程序在哪里?这将从服务器返回所有内容——标头和数据。