【问题标题】:How can I get response body / response text in Electron from headers如何从标题中获取 Electron 中的响应正文/响应文本
【发布时间】:2021-05-19 16:01:15
【问题描述】:

现在,我知道如何获取标头,但是如何获取响应正文/响应文本并不是很容易理解。 我用电子

details.responseHeaders[""].toString(); // Return an object

不返回响应正文,但我必须从标题中获取它,所以我在不同的论坛上搜索了,我没有找到

【问题讨论】:

    标签: node.js header electron response


    【解决方案1】:

    我前段时间也遇到过同样的问题,你可以使用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'); 
    

    【讨论】:

      猜你喜欢
      • 2014-06-15
      • 1970-01-01
      • 1970-01-01
      • 2012-05-02
      • 1970-01-01
      • 2019-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多