电子中的Http请求

Jav*_*ios 5 javascript jquery http httprequest electron

我正在用Electronic做一个桌面应用程序,我需要向php发出一个http请求以关闭服务器上的会话。

情况是,会话完全关闭,但是http.get(选项,函数(res){})中的内容不起作用,就像我不在此处输入

我给你下面的代码

var http = require('http');
    var options = {
      host: localStorage.getItem('server'),
      port: localStorage.getItem('port'),
      path: localStorage.getItem('directori') + '?nosession=1&call=ciberFiSessio&numSerie='+ localStorage.getItem("pc")
    };
    http.get(options, function(res) {
      alert("hola");
      if (res.statusCode  == 200){
        alert("hola");
        //reinicia();

        res.on('data', function (chunk) {
          str = chunk;
          alert(str);

          var myJSON = JSON.parse(str);
          //alert(myJSON.fi);

          if(parseInt(myJSON.fi)==0){
            alert("Hi ha hagut un problema!");
          }else{
            reinicia();
          }

        });

      }else{
        alert("El lloc ha caigut!");
        alert(res.statusCode);
      }
    }).on('error', function(e) {
      alert("Hi ha un error: " + e.message);
    });
Run Code Online (Sandbox Code Playgroud)