【发布时间】:2021-05-19 16:01:15
【问题描述】:
现在,我知道如何获取标头,但是如何获取响应正文/响应文本并不是很容易理解。 我用电子
details.responseHeaders[""].toString(); // Return an object
不返回响应正文,但我必须从标题中获取它,所以我在不同的论坛上搜索了,我没有找到
【问题讨论】:
标签: node.js header electron response
现在,我知道如何获取标头,但是如何获取响应正文/响应文本并不是很容易理解。 我用电子
details.responseHeaders[""].toString(); // Return an object
不返回响应正文,但我必须从标题中获取它,所以我在不同的论坛上搜索了,我没有找到
【问题讨论】:
标签: node.js header electron response
我前段时间也遇到过同样的问题,你可以使用electron debugger API来获取响应体和标头,目前webRequest无法获取响应体。
这是答案:https://stackoverflow.com/a/66675347/13752696
但基本上:
try {
mainWindow.webContents.debugger.attach('1.3');
} catch (err) {
console.log('Debugger attach failed: ', err);
}
mainWindow.webContents.debugger.on('detach', (event, reason) => {
console.log('Debugger detached due to: ', reason);
});
mainWindow.webContents.debugger.on('message', (event, method, params) => {
if (method === 'Network.responseReceived') {
console.log(params.response.url);
mainWindow.webContents.debugger.sendCommand('Network.getResponseBody', { requestId: params.requestId }).then(function(response) {
console.log(response);
});
}
});
mainWindow.webContents.debugger.sendCommand('Network.enable');
【讨论】: