Node.js http.get

Hac*_*tly 11 javascript proxy node.js

我有以下代码请求Google.com主页,并将页面数据发送回客户端的Iframe.

 var options = {
    host: 'www.google.com',
    port: 80,
    path: '/',
    method: 'GET'
  };

  var req = http.get(options, function(res) {
    var pageData = "";
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
      pageData += chunk;
    });

    res.on('end', function(){
      response.send(pageData)
    });
  });
Run Code Online (Sandbox Code Playgroud)

但是,所有图片和CSS都在iframe中被破坏了?如何保存图像和CSS?

Ger*_*ben 11

最简单的解决方案是将<base href ="http://google.com/">添加到html.最好在头部,在'<head>'上更换字符串,并用'<head> <base href ="http://google.com/">'替换