我正在尝试获取在发送请求之前添加的请求对象的选项和后数据
对于报告,使用具有请求和响应结果的数据的一种状态会更有用
function request(options, postData) {
const Module = protocol==='https:' ? https : http;
return new Promise((resolve, reject) => {
const req = Module.request(options);
req.on('response', resolve);
req.on('error', reject);
postData && req.write(postData);
req.end();
});
}
const options = { ... };
const postData = { ... };
request(options, postData)
.then(response => {
// How to get this data?
console.log(response.req.options);
console.log(response.req.postData);
})
.catch(console.error);