标签: node-https

Cloudflare 522 错误 - javascript 客户端连接到节点服务器

我正在尝试从 apache Web 服务器托管的 javascript 客户端连接到 nodejs https 服务器,但收到一条错误消息:522 - Failed to load response data: No data found for resource with given indentifier。apache Web 服务器与节点服务器在同一域/服务器上运行,并且服务器由 Cloudflare 代理:

两种服务都在同一服务器/机器上运行。这就是我启动nodejs服务器的方式:

// Certificates are the same used by apache web server in Virtual Host 
// and were got from Cloud Flare Panel > SSL/TLS > Origin Server
var options = {
  key: fs.readFileSync('/etc/cloudflare/example.com.key'),
  cert: fs.readFileSync('/etc/cloudflare/example.com.pem'),
};

var socket = …
Run Code Online (Sandbox Code Playgroud)

node.js cloudflare node-https

6
推荐指数
1
解决办法
557
查看次数

Node标准https和node-fetch在提供证书时的区别

ADP 的 REST API 要求每次请求时都发送 SSL 证书和私钥。

当我使用“标准 Node.js HTTP(S) 模块”时:

require('dotenv').config()

const fs = require('fs')
const path = require('path')

const certificate_path = path.resolve('../credentials/certificate.pem')
const private_key_path = path.resolve('../credentials/private.key')

const options = {
    hostname: 'api.adp.com',
    path: '/hr/v2/workers/ABCDEFGHIJKLMNOP',
    method: 'GET',
    headers: {
        'Accept': 'application/json;masked=false',
        'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`
    },
    cert: fs.readFileSync(certificate_path, "utf8"),
    key: fs.readFileSync(private_key_path, "utf8"),
};

require('https').get(options, res => {

  let data = [];

  res.on('data', chunk => {
    data.push(chunk);
  });

  res.on('end', () => {

    const workers = JSON.parse(Buffer.concat(data).toString());

    for(worker of workers.workers) {
      console.log(`Got …
Run Code Online (Sandbox Code Playgroud)

javascript client-certificates node.js node-https node-fetch

6
推荐指数
2
解决办法
2841
查看次数

Trello 响应“无效密钥”

我正在尝试使用以下 URL 获取 Trello 板的 JSON 数据,使用 Node.js 的https模块:

https://trello.com/b/nC8QJJoZ.json

这是我的代码:

var https = require('https');

https.get('https://trello.com/b/nC8QJJoZ.json', function (res) {
    console.log('statusCode:', res.statusCode);
    console.log('headers:');
    console.log(res.headers);
    res.setEncoding('utf8');

    res.on('data', function (chunk) {
        console.log(chunk);
    });
}).on('error', function (e) {
    console.log('ERROR: ' + e);
});
Run Code Online (Sandbox Code Playgroud)

尽管 URL 在浏览器中运行良好,但它返回一个包含字符串“无效密钥”的正文,状态为 401。以下是输出:

statusCode: 401
headers:
{ 'cache-control': 'max-age=0, must-revalidate, no-cache, no-store',
  'x-content-type-options': 'nosniff',
  'strict-transport-security': 'max-age=15768000',
  'x-xss-protection': '1; mode=block',
  'x-frame-options': 'DENY',
  'x-trello-version': '1.430.0',
  'x-trello-environment': 'Production',
  'set-cookie':
   [ 'dsc=ae78a354044f982079cd2b5d8adc4f334cda679656b3539ee0adaaf019aee48e; Path=
     'visid_incap_168551=/NYMaLRtR+qQu/H8GYry1BCKl1UAAAAAQUIPAAAAAAC1zWDD1JLPowdC
     'incap_ses_218_168551=+/2JSB4Vz0XJO/pWbX4GAxCKl1UAAAAA0pAbbN5Mbs4tFgbYuskVPw
  expires: 'Thu, 01 Jan 1970 00:00:00',
  'content-type': …
Run Code Online (Sandbox Code Playgroud)

node.js trello node-https

5
推荐指数
1
解决办法
2015
查看次数

使用axios.get时,套接字挂断,但使用https.get时,套接字挂断

据我所知,我正在使用两种不同的方法来做同一件事:

const https = require("https");
const axios = require("axios");

let httpsAgent = new https.Agent({rejectUnauthorized: false});

axios.get(`https://${hostname}:${port}${path}`, {httpsAgent})
    .then((data) => { console.log("axios success: " + data.substr(0, 100)); })
    .catch((error) => { console.log("axios error: " + error); });

let data = "";
https.get({ hostname, path, port, agent: httpsAgent },
    (response) => {
        response.on("data", (chunk) => { data += chunk; });
        response.on("end", () => { console.log("https success: " + data.substr(0, 100)); });
    })
    .on("error", (error) => { console.log("https error: " + error); }); …
Run Code Online (Sandbox Code Playgroud)

javascript https node.js node-https axios

2
推荐指数
1
解决办法
5395
查看次数

如何限制从nodejs http模块上的其余服务器传入的块的大小?

我正在使用 Node.js 请求模块向 Node.js 请求休息服务器。如果传入数据大小超出允许的限制,我想取消流。这样做的目的是确保我的网络没有被锁定。

我的代码示例如下;

var http = require("http");

async function httpRequest({
  host,
  method,
  port,
  path
} = params, data) {
  if (method.toUpperCase() === "GET") {
    let query = "";
    data = JSON.parse(data);

    for (var key in data) {
      if (data.hasOwnProperty(key)) {
        let value = data[key];
        console.log(key + " -> " + value);
        query = query
          .concat("&")
          .concat(key)
          .concat("=")
          .concat(value);
      }
    }
    if (query) {
      query = "?".concat(query.substring(1));
    }
    path = encodeURI(path.concat(query));
    console.log("path : " + path);
  }
  var …
Run Code Online (Sandbox Code Playgroud)

javascript stream node.js node-https

0
推荐指数
1
解决办法
4273
查看次数