I'm using: 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}`);
});
Axios:
axios
.get(`${someUrl}`)
.then(function(response) {
buildResponse(response).then(results => res.send(results));
})
.catch(function(error) {
handleError(error, res);
});
I just get a 503 in the catch, with "Request failed with status code 503"
A GET request can be made with Axios to “get” data from a server. The HTTP get request is performed by calling axios. get() .
Axios works by making HTTP requests with NodeJS and XMLHttpRequests on the browser. If the request was successful, you will receive a response with the data requested. If the request failed, you will get an error. You can also intercept the requests and responses and transform or modify them.
Axios has the ability to intercept HTTP requests. Fetch, by default, doesn't provide a way to intercept requests. Axios has built-in support for download progress. Fetch does not support upload progress.
An HTTP GET request is used to request a specified resource from a server. These requests do not contain any payload with them, i.e., the request doesn’t have any content. Axios GET is the method to make HTTP GET requests using the Axios library.
GET request using axios with React hooks This sends the same GET request from React using axios, but this version uses React hooks from a function component instead of lifecycle methods from a traditional React class component.
Axios is isomorphic, which means it can run in the browser and Node.js with the same code. When used on the server side, it uses Node’s native http module, whereas, on the client side, it uses XMLHttpRequests. On the client side, Axios also supports protection against XSRF. What is the Axios GET method?
I'd like to start using axios over request-promise but proxy support is a deal breaker. I believe axios is trying to determine proto for proxy based on request url (it shouldn't as my proxy is http but the request url is https).
It seems that you can pass Proxy details to Axios FYI.
From the docs...
// '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'
}
},
The only thing that worked for me was unsetting the proxy:
delete process.env['http_proxy'];
delete process.env['HTTP_PROXY'];
delete process.env['https_proxy'];
delete process.env['HTTPS_PROXY'];
From: Socket hang up when using axios.get, but not when using https.get
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With