2

I am trying to send a POST http request with data, but it was taking too long! so I followed the Electron Documentation same example code and it turns out to be slow too. It is taking around 40 SECONDS for 'response' event to fire and return back data!!

Sample code from https://electronjs.org/docs/api/net

const { app } = require('electron')
app.on('ready', () => {
  const { net } = require('electron')
  const request = net.request('https://github.com')
  request.on('response', (response) => {
    console.log(`STATUS: ${response.statusCode}`)
    console.log(`HEADERS: ${JSON.stringify(response.headers)}`)
    response.on('data', (chunk) => {
      console.log(`BODY: ${chunk}`)
    })
    response.on('end', () => {
      console.log('No more data in response.')
    })
  })
  request.end()
})

I used nodejs http module and it works fine but I am wondering why is Electron's native module taking that long to return results?

motash
  • 557
  • 5
  • 8
  • Possible duplicate of [Delays in HTTP requests via Node.js compared to browser](https://stackoverflow.com/questions/28894611/delays-in-http-requests-via-node-js-compared-to-browser) – vladwoguer Apr 04 '19 at 19:19
  • couldn't figure out how does the solution you linked relates to Electron net module being slow in my case? – motash Apr 04 '19 at 21:43
  • The net module uses Chromium's native networking library. So it is similar to using the browser. I tested your code, and I get the response very fast. Are you using a proxy? – vladwoguer Apr 05 '19 at 13:51
  • Please check if this is related with your problem: https://github.com/electron/electron/issues/13829 – vladwoguer Apr 05 '19 at 14:17
  • I have seen that too, I am not running the same setup like the one who raised the issue (windwos 7 with virtual box ), but It's not nearly close to the slow results I am getting :/ – motash Apr 05 '19 at 16:02

1 Answers1

1

I've faced the same problem. In my case, my company makes use of a proxy, so my requests spent too much time (about 40 seconds as in your case). My solution was the use Node HTTP requests (with axios using the proxy: false).

thCosta
  • 44
  • 3