簡體   English   中英

node.js get https 無響應 504

[英]node.js get https no responding 504

我正在嘗試在我的后端 node.js web 應用程序中發出 https 請求。 我有以下代碼:

const express = require('express');
const https = require('https');

const app = express();

app.get("/", function(req, res) {

  const url = "https://www.tkmaxx.com/uk/en/women/edits/big-brand-drop/c/01240000/autoLoad?page=1"
  https.get(url, function(response) {

    console.log(response.statusCode);

  });
  res.send("running test")
});

app.listen(3000, function() {
  console.log("Server started on port 3000");
});

我收到以下錯誤:

node:events:504
      throw er; // Unhandled 'error' event
      ^

Error: socket hang up
    at connResetException (node:internal/errors:691:14)
    at TLSSocket.socketOnEnd (node:_http_client:466:23)
    at TLSSocket.emit (node:events:538:35)
    at endReadableNT (node:internal/streams/readable:1345:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) 
Emitted 'error' event on ClientRequest instance at:
    at TLSSocket.socketOnEnd (node:_http_client:466:9)
    at TLSSocket.emit (node:events:538:35)
    at endReadableNT (node:internal/streams/readable:1345:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {   code: 'ECONNRESET' }

有人知道發生了什么事嗎? 問題與請求標頭或用戶代理有關嗎? 我該如何設置?

如果遠程服務器具有Accept header 和Connection: keep-alive ,則該請求僅被遠程服務器接受。 (這些是瀏覽器通常設置的標頭。)

https.get("https://www.tkmaxx.com/uk/en/women/edits/big-brand-drop/c/01240000/autoLoad?page=1", {
  headers: {
    accept: "text/html",
    connection: "keep-alive"
  }
}, function(response) {...});

(也許這是遠程服務器用來防止瀏覽器以外的客戶端發出的請求的一種機制?)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM