Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Office js 如何从office.js代码内部连接服务器_Office Js - Fatal编程技术网

Office js 如何从office.js代码内部连接服务器

Office js 如何从office.js代码内部连接服务器,office-js,Office Js,我正在开发一个office.js应用程序。我还开发了一个express服务器,它运行并等待http请求。 但我在如何连接这两个部分上遇到了麻烦。(两个代码都是用节点技术编写的) 在另一段代码中,我尝试使用http模块将post请求从office.js应用程序发送到express服务器,但没有成功。 以下是office.js应用程序中的代码: const data = JSON.stringify({ userid : 8888, username : 'excell sendin

我正在开发一个office.js应用程序。我还开发了一个express服务器,它运行并等待http请求。 但我在如何连接这两个部分上遇到了麻烦。(两个代码都是用节点技术编写的) 在另一段代码中,我尝试使用http模块将post请求从office.js应用程序发送到express服务器,但没有成功。 以下是office.js应用程序中的代码:

const data = JSON.stringify({
    userid : 8888,
    username : 'excell sending info - third test'
  })



const options = {
  hostname: 'localhost',
  port: 8888,
  path: '/test',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Content-Length': data.length
  }
}

const req = http.request(options, (res) => {
  console.log(`statusCode: ${res.statusCode}`)

  res.on('data', (d) => {
    process.stdout.write(d)
  })
})

req.on('badRequest', (error) => {
  console.error(error)
})
//OfficeHelpers.UI.notify();
req.write(data)
req.end()





    });
} catch (error) {
    OfficeHelpers.UI.notify(error);
    OfficeHelpers.Utilities.log(error);
}
}

Wireshark表示有一个错误的请求。
非常感谢你的帮助

您正在使用Office.js构建Office插件,这太好了。您在本地运行的Express服务器是否在https上运行?正如您所知,作为一种安全措施,加载项只能使用https加载并连接到也使用https的站点/服务。您可以从我们拥有的最新模板中看到,我们还创建了一个简单的网页包dev server,它使用https和自动生成的dev-cert。请查看该模板以获取有关如何生成证书和为服务器配置证书的示例。

作为Express.js上的一个快速、随机的指针,我发现这个博客很有帮助:
我希望这对你有帮助

通过使用HTTPS并创建所需的证书,问题得以解决。
然后请求就可以正确地发送到服务器。

谢谢您的回答!我跟随你发给我的博客,看到下面一行创建自签名证书:openssl req-nodes-new-x509-keyout server.key-out server.cert为了让它工作,我应该在哪里写上面的命令?我厌倦了CMD,收到一条消息说openssl无法识别..Hi@LouMM我完成了所有必需的步骤,现在express服务器正在https上运行。问题在于excel代码。当我试图通过https quries从我的office.js应用程序访问服务器时,它不起作用。请问我错过了什么?