添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Describe the bug

Axios returns ECONNREFUSED 127.0.0.1:80 but port is set to 8080

To Reproduce

While having an express server returning 200 on http://localhost:8080/ (and confirmed via browser), running the following returns the error provided (see additional context)

axios({
  headers: { Accept: 'text/html, application/json, text/plain, */*' },
  proxy: undefined,
  url: 'http://localhost:8080',
  method: 'get'
});

Expected behavior

Axios sends an http request to the port specified in the url

Environment

Im indirectly using [email protected] (start-server-and-test -> wait-on -> [email protected]).

  • Axios Version [0.21.1
  • Adapter HTTP
  • Node.js Version v12.8.0 and v15.8.0
  • OS: macOS 10.15.6
  • Additional context/Screenshots

    Error:

    Error: connect ECONNREFUSED 127.0.0.1:80
        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1056:14) {
      errno: 'ECONNREFUSED',
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '127.0.0.1',
      port: 80,
      config: {
        url: 'http://localhost:8080',
        method: 'get',
        headers: {
          Accept: 'text/html, application/json, text/plain, */*',
          'User-Agent': 'axios/0.21.1',
          host: 'localhost:8080'
        transformRequest: [ [Function: transformRequest] ],
        transformResponse: [ [Function: transformResponse] ],
        timeout: 0,
        adapter: [Function: httpAdapter],
        xsrfCookieName: 'XSRF-TOKEN',
        xsrfHeaderName: 'X-XSRF-TOKEN',
        maxContentLength: -1,
        maxBodyLength: -1,
        httpsAgent: Agent {
          _events: [Object: null prototype],
          _eventsCount: 1,
          _maxListeners: undefined,
          defaultPort: 443,
          protocol: 'https:',
          options: [Object],
          requests: {},
          sockets: {},
          freeSockets: {},
          keepAliveMsecs: 1000,
          keepAlive: false,
          maxSockets: Infinity,
          maxFreeSockets: 256,
          maxCachedSessions: 100,
          _sessionCache: [Object]
        validateStatus: [Function: validateStatus],
        data: undefined
      request: Writable {
        _writableState: WritableState {
          objectMode: false,
          highWaterMark: 16384,
          finalCalled: false,
          needDrain: false,
          ending: false,
          ended: false,
          finished: false,
          destroyed: false,
          decodeStrings: true,
          defaultEncoding: 'utf8',
          length: 0,
          writing: false,
          corked: 0,
          sync: true,
          bufferProcessing: false,
          onwrite: [Function: bound onwrite],
          writecb: null,
          writelen: 0,
          bufferedRequest: null,
          lastBufferedRequest: null,
          pendingcb: 0,
          prefinished: false,
          errorEmitted: false,
          emitClose: true,
          autoDestroy: false,
          bufferedRequestCount: 0,
          corkedRequestsFree: [Object]
        writable: true,
        _events: [Object: null prototype] {
          response: [Function: handleResponse],
          error: [Function: handleRequestError]
        _eventsCount: 2,
        _maxListeners: undefined,
        _options: {
          maxRedirects: 21,
          maxBodyLength: 10485760,
          protocol: 'http:',
          path: 'http://localhost:8080/',
          method: 'GET',
          headers: [Object],
          agent: undefined,
          agents: [Object],
          auth: undefined,
          hostname: null,
          port: null,
          host: null,
          beforeRedirect: [Function: beforeRedirect],
          nativeProtocols: [Object],
          pathname: 'http://localhost:8080/'
        _ended: true,
        _ending: true,
        _redirectCount: 0,
        _redirects: [],
        _requestBodyLength: 0,
        _requestBodyBuffers: [],
        _onNativeResponse: [Function],
        _currentRequest: ClientRequest {
          _events: [Object: null prototype],
          _eventsCount: 7,
          _maxListeners: undefined,
          outputData: [],
          outputSize: 0,
          writable: true,
          _last: true,
          chunkedEncoding: false,
          shouldKeepAlive: false,
          useChunkedEncodingByDefault: false,
          sendDate: false,
          _removedConnection: false,
          _removedContLen: false,
          _removedTE: false,
          _contentLength: 0,
          _hasBody: true,
          _trailer: '',
          finished: true,
          _headerSent: true,
          socket: [Socket],
          connection: [Socket],
          _header: 'GET http://localhost:8080/ HTTP/1.1\r\n' +
            'Accept: text/html, application/json, text/plain, */*\r\n' +
            'User-Agent: axios/0.21.1\r\n' +
            'host: localhost:8080\r\n' +
            'Connection: close\r\n' +
            '\r\n',
          _onPendingData: [Function: noopPendingOutput],
          agent: [Agent],
          socketPath: undefined,
          method: 'GET',
          path: 'http://localhost:8080/',
          _ended: false,
          res: null,
          aborted: false,
          timeoutCb: null,
          upgradeOrConnect: false,
          parser: null,
          maxHeadersCount: null,
          _redirectable: [Circular],
          [Symbol(isCorked)]: false,
          [Symbol(outHeadersKey)]: [Object: null prototype]
        _currentUrl: 'http:http://localhost:8080/'
      response: undefined,
      isAxiosError: true,
      toJSON: [Function: toJSON]