JS在线运行

版本:
运行结果
教程手册
代码仓库
极速运行
终端运行
图形+终端

                        
以下是用户最新保存的代码
某人准备跑20圈来锻炼自己的身体,他准备分多次(>1)跑完,每次都跑正整数圈,然后休息下再继续跑。 发布于:2023-12-02 11:32 输入一个由小写字母a-z以及左括号(和有括号)组成的字符串s,尽可能少的删除括号,使得字符串中的括号匹配,返回删除括号后的字符串。(输出不唯一) 发布于:2023-12-01 12:27 excel的图片处理JS 发布于:2023-12-01 10:20 括号匹配的增强版本,要求输出括号里的内容 发布于:2023-11-30 12:36 学习js的第二天 不知道代码有没有错 发布于:2023-11-29 20:33 学习代码的第二天 1. 自定义程序: -**gcd**(最大公因数) 发布于:2023-11-29 20:12 策略执行流程部分示例代码 发布于:2023-11-29 20:31 堆排序的实现 发布于:2023-11-27 22:36 在线人数显示 发布于:2023-11-26 11:46 初学者的呻吟! 发布于:2023-11-24 13:44 新共享员工工作量明细查询 发布于:2023-11-23 10:11 JS堆排序 发布于:2023-11-22 21:00 大根堆自顶向下 发布于:2023-11-22 21:20 交通信号灯 发布于:2023-11-21 09:12 第9章:交通信号灯实践 发布于:2023-11-21 09:20 时间 季姬击鸡记街机 发布于:2023-11-20 22:04 hello world 发布于:2023-11-20 13:00 hello world 发布于:2023-11-20 13:01 验证Promise.all嵌套Promsie.all的执行顺序 发布于:2023-11-17 16:41 测试运行结果 发布于:2023-11-16 18:21 浪潮PUT请求 发布于:2023-11-16 17:03 url参数 发布于:2023-11-15 11:06 无序数组中的第 K 大元素 发布于:2023-11-14 21:49 快速排序算法 发布于:2023-11-14 21:48 生成器函数 发布于:2023-11-14 20:49 查找一个无序数组中的第 K 大元素 发布于:2023-11-13 20:28 快速排序。 发布于:2023-11-13 20:26 一些常用方法 发布于:2023-11-13 17:36 快速选择排序求第几大数子 发布于:2023-11-12 11:09 快速排序算法 发布于:2023-11-12 10:33 实现数组去重 发布于:2023-11-09 21:53 实现数组的扁平化 发布于:2023-11-09 21:50 kuaipai 第k个 发布于:2023-11-09 17:05 不使用额外数组情况下,实现快速排序 发布于:2023-11-08 14:48 JS 打印过去30天的日期和星期 发布于:2023-11-07 19:57 JS 打印未来30天日期和星期 发布于:2023-11-07 19:55 js 原型 实战 发布于:2023-11-07 10:54 JS prototype 原型 发布于:2023-11-06 16:10 String相关处理函数 发布于:2023-11-06 14:51 求解无序数组中逆序对的个数 发布于:2023-11-06 14:29 归并排序算法 发布于:2023-11-06 14:21 手写apply和bind 发布于:2023-11-06 12:54 vue3源码解析 发布于:2023-11-06 16:16 Javascript数组相关函数 发布于:2023-11-06 11:05 求无序数组中逆序对的个数 发布于:2023-11-06 10:30 求出一组数据的有序对个数或者逆序对个数 发布于:2023-11-05 17:37 归并排序算法 发布于:2023-11-05 15:50 测试代码进制转换 发布于:2023-11-03 17:51 求解无序数组逆序对的个数 发布于:2023-11-02 18:08 归并排序问题 发布于:2023-11-02 17:41 [更多]
显示目录

HTTPS



HTTPS

稳定性: 3 - 稳定

HTTPS是什么?HTTPS是基于TLS/SSL的HTTP协议,在Node.js里它可以作为单独的模块来实现。在本文中,你将了解HTTPS的使用方法。

类: https.Server

https.Server是tls.Server的子类,并且和http.Server一样触发事件。

server.setTimeout(msecs, callback)

server.timeout

https.createServer(options[, requestListener])

返回一个新的HTTPS服务器对象。其中options类似于 [tls.createServer()][tls.md#tls_tls_createserver_options_secureconnectionlistener]。 requestListener函数自动加到'request'事件里。

例如:

// curl -k https://localhost:8000/
var https = require('https');
var fs = require('fs');

var options = {
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};

https.createServer(options, function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}).listen(8000);

或:

var https = require('https');
var fs = require('fs');

var options = {
  pfx: fs.readFileSync('server.pfx')
};

https.createServer(options, function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}).listen(8000);

server.listen(port[, host][, backlog][, callback])

server.listen(path[, callback])

server.listen(handle[, callback])

server.close([callback])

https.request(options, callback)

可以给安全web服务器发送请求。

options可以是一个对象或字符串。如果options是字符串,则会被url.parse()解析。

所有来自http.request()选项都是经过验证的。

例如:

var https = require('https');

var options = {
  hostname: 'encrypted.google.com',
  port: 443,
  path: '/',
  method: 'GET'
};

var req = https.request(options, function(res) {
  console.log("statusCode: ", res.statusCode);
  console.log("headers: ", res.headers);

  res.on('data', function(d) {
    process.stdout.write(d);
  });
});
req.end();

req.on('error', function(e) {
  console.error(e);
});

option参数具有以下的值:

  • host : 请求的服务器域名或IP地址,默认: 'localhost'
  • hostname : 用于支持 url.parse() 。 hostname 优于 host
  • port : 远程服务器端口。默认: 443。
  • method : 指定HTTP请求方法。默认: 'GET' 。
  • path : 请求路径。默认: '/' 。如果有查询字符串,则需要包含。比如 '/index.html?page=12'
  • headers : 包含请求头的对象
  • auth : 用于计算认证头的基本认证,即 user:password
  • agent : 控制Agent的行为。当使用了一个Agent的时候,请求将默认为 Connection: keep-alive 。可能的值为:

    • undefined (default): 在这个主机和端口上使用[global Agent][]
    • Agent object: 在 Agent 中显式使用passed.
    • false : 选择性停用连接池,默认请求为: Connection: close

    tls.connect() 的参数也能指定。但是, globalAgent 会忽略他们。

  • pfx : SSL使用的证书,私钥,和证书Certificate,默认为 null .

  • key : SSL使用的私钥. 默认为 null .
  • passphrase : 私钥或pfx的口令字符串. 默认为 null .
  • cert : 所用公有x509证书. 默认为 null .
  • ca : 用于检查远程主机的证书颁发机构或包含一系列证书颁发机构的数组。
  • ciphers : 描述要使用或排除的密码的字符串
  • rejectUnauthorized : 如为 true 则服务器证书会使用所给CA列表验证。如果验证失败则会触发 error 事件。验证过程发生于连接层,在 HTTP 请求发送之前。默认为 true .
  • secureProtocol : 所用的SSL方法,比如 TLSv1_method 强制使用TLS version 1。可取值取决于您安装的OpenSSL,和定义于 SSL_METHODS 的常量。

要指定这些选项,使用一个自定义 Agent 。

例如:

var options = {
  hostname: 'encrypted.google.com',
  port: 443,
  path: '/',
  method: 'GET',
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};
options.agent = new https.Agent(options);

var req = https.request(options, function(res) {
  ...
}

或者不使用Agent.

例如:

var options = {
  hostname: 'encrypted.google.com',
  port: 443,
  path: '/',
  method: 'GET',
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'),
  agent: false
};

var req = https.request(options, function(res) {
  ...
}

https.get(options, callback)

和 http.get() 类似,不过是HTTPS版本的.

options 可以是字符串对象. 如果 options 是字符串, 会自动使用 url.parse() 解析。

例如:

var https = require('https');

https.get('https://encrypted.google.com/', function(res) {
  console.log("statusCode: ", res.statusCode);
  console.log("headers: ", res.headers);

  res.on('data', function(d) {
    process.stdout.write(d);
  });

}).on('error', function(e) {
  console.error(e);
});

类: https.Agent

HTTPS的Agent对象,和 http.Agent 类似。

https.globalAgent

所有HTTPS客户端请求的 https.Agent 全局实例。

由JSRUN为你提供的JS在线运行、在线编译工具
        JSRUN提供的JS 在线运行,JS 在线运行工具,基于linux操作系统环境提供线上编译和线上运行,具有运行快速,运行结果与常用开发、生产环境保持一致的特点。