axios访问localhost报502错误

发布于 2022-09-06 23:59:35 字数 16674 浏览 22 评论 0

通过axios发起get请求访问本地的html文件http://localhost:8888/public/index.html,报502错误,浏览器正常访问,感觉可能跟本地http代理privoxy有关系,但是把axios的proxy配置到http代理地址上仍然无效。初学者,求解答

{ Error: Request failed with status code 502
    at createError (/Users/JessieKate/Documents/Workspaces/studyDemo/ReactArchitecture/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/Users/JessieKate/Documents/Workspaces/studyDemo/ReactArchitecture/node_modules/axios/lib/core/settle.js:18:12)
    at IncomingMessage.handleStreamEnd (/Users/JessieKate/Documents/Workspaces/studyDemo/ReactArchitecture/node_modules/axios/lib/adapters/http.js:201:11)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
  config: 
   { adapter: [Function: httpAdapter],
     transformRequest: { '0': [Function: transformRequest] },
     transformResponse: { '0': [Function: transformResponse] },
     timeout: 0,
     xsrfCookieName: 'XSRF-TOKEN',
     xsrfHeaderName: 'X-XSRF-TOKEN',
     maxContentLength: -1,
     validateStatus: [Function: validateStatus],
     headers: 
      { Accept: 'application/json, text/plain, */*',
        'User-Agent': 'axios/0.18.0',
        host: 'localhost:8888' },
     method: 'get',
     proxy: { port: 8118, hostname: '10.0.0.32' },
     url: 'http://localhost:8888/public/index.html',
     data: undefined },
  request: 
   ClientRequest {
     domain: null,
     _events: 
      { socket: [Object],
        abort: [Function],
        aborted: [Function],
        error: [Function],
        timeout: [Function],
        prefinish: [Function: requestOnPrefinish] },
     _eventsCount: 6,
     _maxListeners: undefined,
     output: [],
     outputEncodings: [],
     outputCallbacks: [],
     outputSize: 0,
     writable: true,
     _last: true,
     upgrading: false,
     chunkedEncoding: false,
     shouldKeepAlive: false,
     useChunkedEncodingByDefault: false,
     sendDate: false,
     _removedHeader: {},
     _contentLength: 0,
     _hasBody: true,
     _trailer: '',
     finished: true,
     _headerSent: true,
     socket: 
      Socket {
        connecting: false,
        _hadError: false,
        _handle: null,
        _parent: null,
        _host: 'localhost',
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _eventsCount: 8,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        destroyed: true,
        _bytesDispatched: 166,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: null,
        _server: null,
        parser: null,
        _httpMessage: [Circular],
        read: [Function],
        _consuming: true,
        _idleNext: null,
        _idlePrev: null,
        _idleTimeout: -1 },
     connection: 
      Socket {
        connecting: false,
        _hadError: false,
        _handle: null,
        _parent: null,
        _host: 'localhost',
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _eventsCount: 8,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        destroyed: true,
        _bytesDispatched: 166,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: null,
        _server: null,
        parser: null,
        _httpMessage: [Circular],
        read: [Function],
        _consuming: true,
        _idleNext: null,
        _idlePrev: null,
        _idleTimeout: -1 },
     _header: 'GET http://localhost:8888/public/index.html HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nUser-Agent: axios/0.18.0\r\nhost: localhost:8888\r\nConnection: close\r\n\r\n',
     _headers: 
      { accept: 'application/json, text/plain, */*',
        'user-agent': 'axios/0.18.0',
        host: 'localhost:8888' },
     _headerNames: { accept: 'Accept', 'user-agent': 'User-Agent', host: 'host' },
     _onPendingData: null,
     agent: 
      Agent {
        domain: null,
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        defaultPort: 80,
        protocol: 'http:',
        options: [Object],
        requests: {},
        sockets: [Object],
        freeSockets: {},
        keepAliveMsecs: 1000,
        keepAlive: false,
        maxSockets: Infinity,
        maxFreeSockets: 256 },
     socketPath: undefined,
     timeout: undefined,
     method: 'GET',
     path: 'http://localhost:8888/public/index.html',
     _ended: true,
     _redirectable: 
      Writable {
        _writableState: [Object],
        writable: true,
        domain: null,
        _events: [Object],
        _eventsCount: 2,
        _maxListeners: undefined,
        _options: [Object],
        _redirectCount: 0,
        _requestBodyLength: 0,
        _requestBodyBuffers: [],
        _onNativeResponse: [Function],
        _currentRequest: [Circular],
        _currentUrl: 'http:http://localhost:8888/public/index.html' },
     parser: null,
     res: 
      IncomingMessage {
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        socket: [Object],
        connection: [Object],
        httpVersionMajor: 1,
        httpVersionMinor: 1,
        httpVersion: '1.1',
        complete: true,
        headers: [Object],
        rawHeaders: [Object],
        trailers: {},
        rawTrailers: [],
        upgrade: false,
        url: '',
        method: null,
        statusCode: 502,
        statusMessage: 'No data received from server or forwarder',
        client: [Object],
        _consuming: true,
        _dumped: false,
        req: [Circular],
        responseUrl: 'http:http://localhost:8888/public/index.html',
        read: [Function] } },
  response: 
   { status: 502,
     statusText: 'No data received from server or forwarder',
     headers: 
      { 'content-length': '7393',
        'content-type': 'text/html',
        'cache-control': 'no-cache',
        date: 'Wed, 18 Apr 2018 14:25:33 GMT',
        'last-modified': 'Wed, 08 Jun 1955 12:00:00 GMT',
        expires: 'Sat, 17 Jun 2000 12:00:00 GMT',
        pragma: 'no-cache',
        connection: 'close' },
     config: 
      { adapter: [Function: httpAdapter],
        transformRequest: [Object],
        transformResponse: [Object],
        timeout: 0,
        xsrfCookieName: 'XSRF-TOKEN',
        xsrfHeaderName: 'X-XSRF-TOKEN',
        maxContentLength: -1,
        validateStatus: [Function: validateStatus],
        headers: [Object],
        method: 'get',
        proxy: [Object],
        url: 'http://localhost:8888/public/index.html',
        data: undefined },
     request: 
      ClientRequest {
        domain: null,
        _events: [Object],
        _eventsCount: 6,
        _maxListeners: undefined,
        output: [],
        outputEncodings: [],
        outputCallbacks: [],
        outputSize: 0,
        writable: true,
        _last: true,
        upgrading: false,
        chunkedEncoding: false,
        shouldKeepAlive: false,
        useChunkedEncodingByDefault: false,
        sendDate: false,
        _removedHeader: {},
        _contentLength: 0,
        _hasBody: true,
        _trailer: '',
        finished: true,
        _headerSent: true,
        socket: [Object],
        connection: [Object],
        _header: 'GET http://localhost:8888/public/index.html HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nUser-Agent: axios/0.18.0\r\nhost: localhost:8888\r\nConnection: close\r\n\r\n',
        _headers: [Object],
        _headerNames: [Object],
        _onPendingData: null,
        agent: [Object],
        socketPath: undefined,
        timeout: undefined,
        method: 'GET',
        path: 'http://localhost:8888/public/index.html',
        _ended: true,
        _redirectable: [Object],
        parser: null,
        res: [Object] },
     data: '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n<html>\n\n<head>\n  <title>502 - No server or forwarder data received (Privoxy@localhost)</title>\n  <meta http-equiv="Content-Style-Type" content="text/css">\n  <meta http-equiv="Content-Script-Type" content="text/javascript">\n  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n  <meta name="robots" content="noindex,nofollow">\n  <link rel="shortcut icon" href="http://config.privoxy.org/error-favicon.ico">\n  <style type="text/css">\n\n/*\n * CSS for Privoxy CGI and script output\n *\n * $Id: cgi-style.css,v 1.14 2011/09/04 11:09:40 fabiankeil Exp $\n */\n\n/*\n * General rules: Font, Color, Headings, Margins, Links\n */\nbody,td,th { font-family: arial, helvetica, helv, sans-serif; }\nbody { background-color: #ffffff; color: #000000; }\n\nh1 { font-size: 140%; margin: 0px; }\nh2 { font-size: 120%; margin: 0px; }\nh3 { font-size: 110%; margin: 0px; }\n\np,pre  { margin-left: 15px; }\nli { margin: 2px 15px; }\ndl { margin: 2px 15px; }\n\na:link    { color: #0000dd; text-decoration: none; }\na:visited { color: #330099; text-decoration: none; }\na:active  { color: #3333ff; text-decoration: none; }\n\n/*\n * Boxen as Table elements:\n */\ntd.title   { border: solid black 1px; background-color: #dddddd; }\ntd.box     { border: solid black 1px; background-color: #eeeeee; }\ntd.info    { border: solid black 1px; background-color: #ccccff; }\ntd.warning { border: solid black 1px; background-color: #ffdddd; }\n\n/*\n * Special Table Boxen: for nesting, naked container and for\n * the Status field in CGI Output:\n */\ntd.wrapbox { border: solid black 1px; padding: 5px; }\ntd.container { padding: 0px; }\ntd.status  { border: solid black 1px; background-color: #ff0000; color: #ffffff; font-size: 300%; font-weight: bolder; }\n\n/*\n * Same Boxen as <div>s:\n */\ndiv.title    { border: solid black 1px; background-color: #dddddd; margin: 20px; padding: 20px; }\ndiv.box      { border: solid black 1px; background-color: #eeeeee; margin: 20px; padding: 20px; }\ndiv.info     { border: solid black 1px; background-color: #ccccff; margin: 20px; padding: 20px; }\ndiv.warning  { border: solid black 1px; background-color: #ffdddd; margin: 20px; padding: 20px; }\ndiv.wrapbox  { border: solid black 1px;                            margin: 20px; padding:  5px; }\n\n\n/*\n * Bold definitions in <dl>s, grey BG for table headings, transparent (no-bordered) table\n */\ndt { font-weight: bold; }\nth { background-color: #dddddd; }\ntable.transparent { border-style: none}\n\n/*\n * Special purpose paragraphs: Small for page footers,\n * Important for quoting wrong or dangerous examples,\n * Whiteframed for the toggle?mini=y CGI\n */\np.small { font-size: 10px; margin: 0px; }\np.important { border: solid black 1px; background-color: #ffdddd; font-weight: bold; padding: 2px; }\np.whiteframed { margin: 5px; padding: 5px; border: solid black 1px; text-align: center; background-color: #eeeeee; }\n\n/*\n * Links as buttons:\n */\n\ntd.buttons {\n  padding: 2px;\n}\n\na.cmd, td.indentbuttons a, td.buttons a {\n  white-space: nowrap;\n  width: auto;\n  padding: 2px;\n  background-color: #dddddd;\n  color:            #000000;\n  text-decoration: none;\n  border-top:    1px solid #ffffff;\n  border-left:   1px solid #ffffff;\n  border-bottom: 1px solid #000000;\n  border-right:  1px solid #000000;\n}\na.cmd:hover, td.indentbuttons a:hover, td.buttons a:hover {\n  background-color: #eeeeee;\n}\na.cmd:active, td.indentbuttons a:active, td.buttons a:active {\n  border-top:    1px solid #000000;\n  border-left:   1px solid #000000;\n  border-bottom: 1px solid #ffffff;\n  border-right:  1px solid #ffffff;\n}\n\n\n/*\n * Special red emphasis:\n */\nem.warning, strong.warning { color: #ff0000 }\n\n/*\n * In show-status we use tables directly behind headlines\n * and for some reason or another the headlines are set to\n * "margin:0" and leave the tables no air to breath.\n *\n * A proper fix would be to replace or remove the "margin:0",\n * but as this affects every cgi page we do it another time\n * and use this workaround until then.\n */\n.box table { margin-top: 1em; }\n\n/*\n * Let the URL and pattern input fields scale with the browser\n * width and try to prevent vertical scroll bars if the width\n * is less than 80 characters.\n */\ninput.url, input.pattern { width: 95%; }\n  </style>\n</head>\n\n<body>\n\n  <table summary="" cellpadding="20" cellspacing="10" border="0" width="100%">\n    <tr>\n      <td class="status">\n        502\n      </td>\n      <td class="title" style="width: 100%">\n\n        <h1>\n          This is <a href="https://www.privoxy.org/">Privoxy</a> 3.0.26 on localhost (127.0.0.1), port 8118<!-- @if-can-toggle-start -->,\n          enabled<!-- if-can-toggle-end@ -->\n        </h1>\n\n      </td>\n    </tr>\n\n<!--  -->\n\n    <tr>\n      <td class="warning" colspan=2>\n        <h2>No server or forwarder data received</h2>\n          <p>Your request for <a href="http://localhost:8888/public/index.html"><b>http://localhost:8888/public/index.html</b></a>\n          could not be fulfilled, because the connection to <b>localhost</b> (127.0.0.1) has been closed\n          before Privoxy received any data for this request.\n          </p>\n          <p>This is often a temporary failure, so you might just\n            <a href="http://localhost:8888/public/index.html">try again</a>.\n         </p>\n         <p>\n          If you get this message very often, consider disabling\n          <a href="https://www.privoxy.org/3.0.26/user-manual/config.html#CONNECTION-SHARING">connection-sharing</a>\n          (which should be off by default). If that doesn\'t help, you may have to additionally\n          disable support for connection keep-alive by setting\n          <a href="https://www.privoxy.org/3.0.26/user-manual/config.html#KEEP-ALIVE-TIMEOUT">keep-alive-timeout</a>\n          to 0.\n         </p>\n      </td>\n    </tr>\n\n    <tr>\n      <td class="box" colspan="2">\n        <h2>More Privoxy:</h2>\n        <ul><li><a href="http://config.privoxy.org/">Privoxy main page</a></li><li><a href="http://config.privoxy.org/show-status">View &amp; change the current configuration</a></li><li><a href="http://config.privoxy.org/show-version">View the source code version numbers</a></li><li><a href="http://config.privoxy.org/client-tags">View or toggle the tags that can be set based on the clients address</a></li><li><a href="http://config.privoxy.org/show-request">View the request headers</a></li><li><a href="http://config.privoxy.org/show-url-info">Look up which actions apply to a URL and why</a></li><li><a href="https://www.privoxy.org/3.0.26/user-manual/">Documentation</a></li></ul>\n      </td>\n    </tr>\n\n    <tr>\n      <td class="info" colspan="2">\n\n       <h2>Support and Service:</h2>\n        <p>\n          The Privoxy Team values your feedback.\n        </p>\n        <p>\n          Please have a look at the User Manual to learn how to\n          <a title="Privoxy User Manual: Contacting the developers, Bug Reporting and Feature Requests"\n           href="https://www.privoxy.org/3.0.26/user-manual/contact.html">get support or report problems</a>.\n        <p>\n          If you want to support the Privoxy Team, you can\n          <a href="https://www.privoxy.org/faq/general.html#PARTICIPATE">participate</a>\n          or <a href="https://www.privoxy.org/faq/general.html#DONATE">donate</a>.\n        </p>\n\n      </td>\n    </tr>\n\n<!--  -->\n\n  </table>\n\n</body>\n</html>\n' } }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文