Axios requests with proxy fails to redirect properly
See original GitHub issue### Summary
Axios requests with proxy fails to redirect properly, as described below:
The request:
const axios = require('axios')
axios.get('http://testapi.testdomain.com/api/articles/personal/01d76a9844ae4a919f02ddedf11a6fcc?page=2&size=10', {
proxy: {
host: '127.0.0.1',
port: 1080
}
})
.then((response) => {
console.log(response)
})
.catch((err) => {
console.log(err)
})
The response:
$ node axios_promise.js
{ Error: connect ECONNREFUSED 127.0.0.1:80
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 80,
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.17.1' },
method: 'get',
proxy: { host: '127.0.0.1', port: 1080 },
url: 'http://testapi.testdomain.com/api/articles/personal/01d76a9844ae4a919f02ddedf11a6fcc?page=2&size=10',
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,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
domain: null,
_events:
{ response: [Function: handleResponse],
error: [Function: handleRequestError] },
_eventsCount: 2,
_maxListeners: undefined,
_options:
{ maxRedirects: 21,
protocol: 'http:',
hostname: '127.0.0.1',
port: null,
path: '/api/articles/personal/01d76a9844ae4a919f02ddedf11a6fcc?page=2&size=10&uc_param_str=dnvebichntwidsudsvpflameefut',
method: 'GET',
headers: [Object],
agent: undefined,
auth: null,
host: '127.0.0.1',
pathname: '/api/articles/personal/01d76a9844ae4a919f02ddedf11a6fcc',
search: '?page=2&size=10&uc_param_str=dnvebichntwidsudsvpflameefut',
slashes: true,
hash: null,
query: 'page=2&size=10&uc_param_str=dnvebichntwidsudsvpflameefut',
href: 'http://127.0.0.1/api/articles/personal/01d76a9844ae4a919f02ddedf11a6fcc?page=2&size=10&uc_param_str=dnvebichntwidsudsvpflameefut' },
_redirectCount: 1,
_bufferedWrites: [],
_onNativeResponse: [Function],
_currentRequest:
ClientRequest {
domain: null,
_events: [Object],
_eventsCount: 5,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: true,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Object],
connection: [Object],
_header: 'GET /api/articles/personal/01d76a9844ae4a919f02ddedf11a6fcc?page=2&size=10&uc_param_str=dnvebichntwidsudsvpflameefut HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nUser-Agent: axios/0.17.1\r\nHost: 127.0.0.1\r\nConnection: close\r\n\r\n',
_onPendingData: [Function: noopPendingOutput],
agent: [Object],
socketPath: undefined,
timeout: undefined,
method: 'GET',
path: '/api/articles/personal/01d76a9844ae4a919f02ddedf11a6fcc?page=2&size=10&uc_param_str=dnvebichntwidsudsvpflameefut',
_ended: false,
res: null,
aborted: undefined,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
_redirectable: [Circular],
[Symbol(outHeadersKey)]: [Object] },
_currentUrl: 'http://127.0.0.1/api/articles/personal/01d76a9844ae4a919f02ddedf11a6fcc?page=2&size=10&uc_param_str=dnvebichntwidsudsvpflameefut',
_isRedirect: true },
response: undefined }
Please note the error part of response at the top:
{ Error: connect ECONNREFUSED 127.0.0.1:80
at Object.exports._errnoException (util.js:1022:11)
and the response part at the bottom:
_currentUrl: 'http://127.0.0.1/api/articles/personal/01d76a9844ae4a919f02ddedf11a6fcc?page=2&size=10&uc_param_str=dnvebichntwidsudsvpflameefut',
_isRedirect: true },
What I got is http://127.0.0.1/api/articles/personal/01d76a9844ae4a919f02ddedf11a6fcc?page=2&size=10&uc_param_str=dnvebichntwidsudsvpflameefut
,
and what I expect should be
http://testapi.testdomain.com/api/articles/personal/01d76a9844ae4a919f02ddedf11a6fcc?page=2&size=10&uc_param_str=dnvebichntwidsudsvpflameefut
### Context
- axios version: v0.17.1
- Environment: node vv8.1.4, windows 10
Issue Analytics
- State:
- Created 6 years ago
- Reactions:12
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Set proxy for terminal and I cannot redirect properly using axios
After set proxy i cannot redirect properly. This is part of the error log, and i can clearly find the the _currentUrl is...
Read more >How to Fix The ERR_TOO_MANY_REDIRECTS Error - Kinsta
We come across a lot of different errors here at Kinsta, and ERR_TOO_MANY_REDIRECTS (also known as a redirect loop) is one we see...
Read more >407 Proxy Authentication Required - HTTP - MDN Web Docs
The HTTP 407 Proxy Authentication Required client error status response code indicates that the request has not been applied because it ...
Read more >http-proxy-middleware - npm
TL;DR. Proxy /api requests to http://www.example.org. // javascript const express ...
Read more >Too Many Redirects: What This Error Means & How to Fix It
Clear cookies on the redirecting website. · Clear your browser cache. · Ensure your SSL certificate is installed correctly. · Evaluate your third- ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Still getting this here
have the same issue as @kidlj, axios seems cannot redirect properly when using proxy