node 反向代理 谷歌

来源:互联网 发布:多线程网络爬虫 编辑:程序博客网 时间:2024/06/05 22:45


先安装      http-proxy




servergoogle.js

'use strict';var http = require('http');var https = require('https');var httpProxy = require('http-proxy');var url = require('url');var PROXY_PORT = 9000;var proxy, server;// Create a proxy server with custom application logicproxy = httpProxy.createProxy({});proxy.on('error', function (err) {    console.log('ERROR');    console.log(err);});server = http.createServer(function (req, res) {    //var finalUrl = req.url,    var finalUrl = 'https://www.google.com.hk';    var finalAgent = null;    var parsedUrl = url.parse(finalUrl);        console.log(' ' + new Date().getTime() );    if (parsedUrl.protocol === 'https:') {        finalAgent = https.globalAgent;    } else {        finalAgent = http.globalAgent;    }    proxy.web(req, res, {        target: finalUrl,        agent: finalAgent,        headers: { host: parsedUrl.hostname },        prependPath: false,        xfwd : true,        hostRewrite: finalUrl.host,        protocolRewrite: parsedUrl.protocol    });});console.log('listening on port ' + PROXY_PORT);server.listen(PROXY_PORT);



反向代理谷歌.bat

@echo oncd %cd%node servergoogle.js








运行:















原创粉丝点击