Axios GET request not working

I use: Axios: 0.17.1 Node: 8.0.0

The following standard Node get works fine, but the Axios version does not. Any ideas why?

Node http:

    http
    .get(`${someUrl}`, response => {
        buildResponse(response).then(results => res.send(results));
    })
    .on('error', e => {
        console.error(`Got error: ${e.message}`);
    });

Vardar:

axios
    .get(`${someUrl}`)
    .then(function(response) {
        buildResponse(response).then(results => res.send(results));
    })
    .catch(function(error) {
        handleError(error, res);
    });

I just get 503 in catch, with "Request failed with status code 503"

+4
source share
3 answers

It seems that you can pass proxy data to Axios FYI.

From the documents ...

  // 'proxy' defines the hostname and port of the proxy server
  // Use `false` to disable proxies, ignoring environment variables.
  // `auth` indicates that HTTP Basic auth should be used to connect to the proxy, and
  // supplies credentials.
  // This will set an `Proxy-Authorization` header, overwriting any existing
  // `Proxy-Authorization` custom headers you have set using `headers`.
  proxy: {
    host: '127.0.0.1',
    port: 9000,
    auth: {
      username: 'mikeymike',
      password: 'rapunz3l'
    }
  },
+2
source

The only thing that worked for me was disabling the proxy:

delete process.env['http_proxy'];
delete process.env['HTTP_PROXY'];
delete process.env['https_proxy'];
delete process.env['HTTPS_PROXY'];

C: Socket freezes when using axios.get, but not when using https.get

0
source

I think you could forget to return the axiom answer.

return axios
    .get(`${someUrl}`)
    .then(function(response) {
        return buildResponse(response).then(results => res.send(results));
    })
    .catch(function(error) {
        handleError(error, res);
    });

Pay attention to return before axios.get and before buildResponse

0
source

Source: https://habr.com/ru/post/1689698/


All Articles