sinat_37552373 2022-08-05 18:01 采纳率: 33.3%
浏览 23
已结题

node.js请求的时候出现错误socket hang up

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)

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 8月13日
    • 创建了问题 8月5日

    悬赏问题

    • ¥15 Questasim Error: (vcom-13)
    • ¥15 船舶旋回实验matlab
    • ¥30 SQL 数组,游标,递归覆盖原值
    • ¥15 为什么我的数据接收的那么慢呀有没有完整的 hal 库并 代码呀有的话能不能发我一份并且我用 printf 函数显示处理之后的数据,用 debug 就不能运行了呢
    • ¥15 有关于推荐系统jupyter
    • ¥20 gitlab 中文路径,无法下载
    • ¥15 用动态规划算法均分纸牌
    • ¥30 udp socket,bind 0.0.0.0 ,如何自动选取用户访问的服务器IP来回复数据
    • ¥15 关于树的路径求解问题
    • ¥15 yolo在训练时候出现File "D:\yolo\yolov5-7.0\train.py"line 638,in <module>