鍍金池/ 問(wèn)答/HTML/ node https請(qǐng)求返回code: 'ECONNRESET',

node https請(qǐng)求返回code: 'ECONNRESET',

const https = require('https');

var options = {
    hostname: 'web.4jc33.com',
    port: 80,
    path: '/lotts/times?ids=cqssc',
    headers: {
        'Content-Type': 'application/json; charset=utf-8',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36',
        'Referer': 'https://web.4jc33.com/lotts/cqssc/index',
        'Cookie': 'guide1=xianyu; openSwitching=n657; JSESSIONID=4BA58696365A8AD51F0A5802A80D44306C693CEA'
    },
 };


https.get(options, (res) => {
  console.log('statusCode:', res.statusCode);
  console.log('headers:', res.headers);

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

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

// 返回

{ Error: socket hang up
    at TLSSocket.onHangUp (_tls_wrap.js:1135:19)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at TLSSocket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1056:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
  code: 'ECONNRESET',
  path: null,
  host: 'web.4jc33.com',
  port: 80,
  localAddress: undefined }

代碼如上,請(qǐng)求https的鏈接不能正確的返回,瀏覽器能打開

回答
編輯回答
挽歌

已解決:https默認(rèn)端口443

2018年4月8日 06:59