Ben*_*ros 5 javascript get http node.js axios
我正在使用:Axios:0.17.1 节点:8.0.0
下面的标准 Node get 工作正常,但 Axios 版本不行。任何想法为什么?
节点 http:
http
.get(`${someUrl}`, response => {
buildResponse(response).then(results => res.send(results));
})
.on('error', e => {
console.error(`Got error: ${e.message}`);
});
Run Code Online (Sandbox Code Playgroud)
轴:
axios
.get(`${someUrl}`)
.then(function(response) {
buildResponse(response).then(results => res.send(results));
})
.catch(function(error) {
handleError(error, res);
});
Run Code Online (Sandbox Code Playgroud)
我刚收到一个 503,“请求失败,状态码 503”
看来您可以将代理详细信息传递给 Axios FYI。
从文档中...
// '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'
}
},
Run Code Online (Sandbox Code Playgroud)