【问题标题】:ECONNREFUSED 127.0.0.1:443ECONNREFUSED 127.0.0.1:443
【发布时间】:2020-12-11 19:42:00
【问题描述】:

为什么会向 localhost 发出这个请求:

 {
  errno: -4078,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 443,
  config: {
    url: 'https:\\stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2f',
    method: 'get',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/0.19.2'
    },

我没有在我的代码中使用本地主机。但由于某种原因,axios 似乎正在使用本地主机。 下面的代码是导致我在测试函数时遇到的当前问题的原因:

function Scraper(url: string, login_page?: string){
  if (login_page) {
    var link: string = 'https:\\' + url + '/' + login_page;
  }
  else {
    var link: string = 'https:\\' + url;
  }
    axios.get(link)
    .then(responce => {
      const html = responce.data;
      const $ = cheerio.load(html);
      const website_usr_field: Cheerio = $('input[type=email]');
      //if ()
      /*
      TODO:
      1) Create if statement for assigning login type variable for values.
      */
      const website_pwd_field: Cheerio = $('input[type=password]');
      console.log(website_usr_field);
      console.log(website_pwd_field);
      return website_usr_field && website_pwd_field;
    }).catch(console.error);
}

【问题讨论】:

  • 您使用的是哪个操作系统?检查是否没有设置代理
  • 如果这就是你所说的操作系统的意思,我正在使用 Windows,我还没有设置代理,@Cyber​​Prodigy
  • 您是否将http_proxyhttps_proxy 设置为环境变量?
  • 我不知道这是否正常,但我都没有。@BNilsou
  • 您是否正在使用任何自定义配置创建 axios 实例?

标签: javascript typescript axios


【解决方案1】:

可能是一个不正确的网址?

改变:

https:\\

到:

https://

【讨论】:

  • 这是否解决了问题?
  • 谢谢,我使用 path.join 连接网址(I shouldn't be),并且网址有“https://”,在使用 path.join 后它被更改为“https:// "
猜你喜欢
  • 2020-09-19
  • 1970-01-01
  • 2021-09-03
  • 2022-12-23
  • 2021-12-22
  • 2021-04-21
  • 2021-02-06
  • 1970-01-01
  • 2019-08-07
相关资源
最近更新 更多