node.js请求的时候出现错误socket hang up
我请求带 ip+port这种就会出错,直接请求就不会报错,下面是我的代码,
大家帮忙看下
比如访问http://192.168.1.157:8400/api/v2/login 这种就会报错
http://www.test.com/api/v2/login%E6%AD%A3%E5%B8%B8
_request (proxy, uReq, uRes) {
const u = url.parse(uReq.url)
const socksAgent = new socks.Agent({
proxy,
target: { host: u.host, port: u.port }
})
const options = {
hostname: u.hostname,
port: u.port || 80,
path: u.path,
method: u.method || 'get',
headers: u.headers,
agent: socksAgent
}
const pReq = http.request(options)
pReq.on('response', pRes => {
pRes.pipe(uRes)
uRes.writeHead(pRes.statusCode, pRes.headers)
this.emit('request:success')
}).on('error', e => {
uRes.writeHead(500)
uRes.end('Connection error\n'+e.message)
this.emit('request:error', e)
})
uReq.pipe(pReq)
}