【问题标题】:HTTP Requests before Electron application show any windowElectron 应用程序显示任何窗口之前的 HTTP 请求
【发布时间】:2017-09-02 19:36:34
【问题描述】:

我想在显示我的应用程序的任何窗口之前对 RESTful API 提出一些请求。有谁知道这样做的好方法?谁能举个例子?

非常感谢。

【问题讨论】:

    标签: json spring-boot electron restful-url


    【解决方案1】:

    您可以将这些 API 调用添加到窗口创建代码所在的 main.js 文件中。

    app.on('ready', function () {
      //make api calls
    
      var request = require('request');
      request('http://www.google.com', function (error, response, body) {
          console.log('error:', error); // Print the error if one occurred 
          console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received 
          console.log('body:', body); // Print the HTML for the Google homepage. 
    
          // Create the browser window.
          mainWindow = new BrowserWindow({ width: 1000, height: 625 });
    
      });     
    
      ...    
    });
    

    【讨论】:

    • 感谢您的及时回复。但是如何在电子中创建 REST API?有什么建议吗?
    • 您可以使用request npm 模块,我已经更新了我的答案。
    猜你喜欢
    • 2017-07-10
    • 2021-01-20
    • 1970-01-01
    • 2011-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-31
    相关资源
    最近更新 更多