1 Star 0 Fork 2

scriptiot / evm_doc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
evm_class_https.md 4.15 KB
一键复制 编辑 原始数据 按行查看 历史
edmundwz 提交于 2021-02-20 16:13 . update

Https

IoT.js provides HTTPS to support HTTPS clients enabling users to send HTTPS requests easily.

https.createServer([options][, requestListener])

  • options {Object} Accepts the same options as tls.createServer and http.createServer methods.
  • requestListener {Function}
    • request {http.IncomingMessage}
    • response {http.ServerResponse}
  • Returns: {https.Server}

To create a server the certificates should be specified via the options object.

The requestListener is a function which is automatically added to the 'request' event.

Example

var options = {
  key: fs.readFileSync('server.key'),
  cert: fs.readFileSync('server.cert')
};
var server = https.createServer(options, function(request, response) {
  ...
});

https.request(options[, callback])

  • options {Object}
    • host {string} A domain name or IP address of the server to issue the request to. Default: 'localhost'.
    • hostname {string} Alias for host.
    • port {number} Port of remote server. Default: 443.
    • method {string} A string specifying the HTTPS request method. Default: 'GET'.
    • path {string} Request path. Default: '/'. Should include query string if any. E.G. '/index.html?page=12'. An exception is thrown when the request path contains illegal characters. Currently, only spaces are rejected but that may change in the future.
    • headers {Object} An object containing request headers.
    • auth {string} Optional Basic Authentication in the form username:password. Used to compute HTTPS Basic Authentication header.
    • ca {string} Optional file path to CA certificate. Allows to override system trusted CA certificates.
    • cert {string} Optional file path to client authentication certificate in PEM format.
    • key {string} Optional file path to private keys for client cert in PEM format.
    • rejectUnauthorized {boolean} Optional Specify whether to verify the Server's certificate against CA certificates. WARNING - Making this false may be a security risk. Default: true
  • callback {Function}
    • response {http.IncomingMessage}
  • Returns: {http.ClientRequest}

Example:

var https = require('https');

var request = https.request({
  method: 'POST',
  port: 443,
  headers: {'Content-Length': 3}
});

...

request.end();

Note that in the example req.end() was called. With https.request() one must always call req.end() to signify that you're done with the request - even if there is no data being written to the request body.

https.get(options[, callback])

  • options {Object}
    • host {string} A domain name or IP address of the server to issue the request to. Default: 'localhost'.
    • hostname {string} Alias for host.
    • port {number} Port of remote server. Default: 443.
    • method {string} A string specifying the HTTPS request method. Default: 'GET'.
    • path {string} Request path. Default: '/'. Should include query string if any. E.G. '/index.html?page=12'. An exception is thrown when the request path contains illegal characters. Currently, only spaces are rejected but that may change in the future.
    • headers {Object} An object containing request headers.
    • auth {string} Optional Basic Authentication in the form username:password. Used to compute HTTPS Basic Authentication header.
    • ca {string} Optional file path to CA certificate. Allows to override system trusted CA certificates.
    • cert {string} Optional file path to client authentication certificate in PEM format.
    • key {string} Optional file path to private keys for client cert in PEM format.
    • rejectUnauthorized {boolean} Optional Specify whether to verify the Server's certificate against CA certificates. WARNING - Making this false may be a security risk. Default: true
  • callback {Function}
    • response {http.IncomingMessage}
  • Returns: {http.ClientRequest}

Same as https.request except that https.get automatically call req.end() at the end.

Example:

var https = require('https');

https.get({
  port: 443,
}, function(res) {
...
});
1
https://gitee.com/scriptiot/evm_doc.git
git@gitee.com:scriptiot/evm_doc.git
scriptiot
evm_doc
evm_doc
master

搜索帮助