CNode

用nodejs写代理转发,好像有哪里不对。

问答
Ccoolicer发布于11 年前最后回复11 年前1 回复6661 浏览0 收藏
 if(req.url == '/data/get' || req.url == 'data/get') {
     var post_data = querystring.stringify({
         proc: 'getConfig'
     });
     console.log('post_data->',post_data)
     var options = {
         host: '192.168.1.246',
         port:80,
         path: '/data/get',       
         method: 'POST',
         headers: {
             'Content-Type': 'application/json; charset=UTF-8',
             'Content-Length': post_data.length
         }
     };
    var body = ''
    var client_req = http.request(options, function(res) {
           console.log("Got response: " + res.statusCode);
           res.on('data',function(d){
           body += d;
      }).on('end', function(){
           console.log(res.headers)
           console.log(body)
      });

     }).on('error', function(e) {
         console.log("Got error: " + e.message);
     })
     client_req.write(post_data)
     client_req.end();
 }```
	
	我需要使用服务器的地址(192.168.1.246),把 localhost/data/get转发给192.168.1.246/data/get
查看回复

回复 (1)

H
hezedu#1·11 年前

用superagent吧

参与回复
登录后即可参与回复。登录