Node.js http.get

发布于 2024-12-01 02:42:33 字数 470 浏览 3 评论 0原文

我有以下代码,用于请求 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)
    });
  });

但是,iframe 中的所有图像和 CSS 都损坏了吗?如何保留图像和 CSS?

I have the following code that requests the Google.com homepage and sends the page data back to an Iframe on the client side.

 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)
    });
  });

However, all images and CSS are broken in the iframe? How can I preserve the images and CSS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧梦荧光笔 2024-12-08 02:42:33

最简单的解决方案是添加

到 html。最好在头部,所以字符串替换在 '' 上并将其替换为 ''

Simplest solution is to add <base href="http://google.com/"> to the html. Preferably in the head, so do string replace on '<head>' and replace in with '<head><base href="http://google.com/">'

银河中√捞星星 2024-12-08 02:42:33

让客户端获取 Google 页面不是更容易吗?

<html>
<head>
<script>
window.onload = function () {
  var nif = document.createElement("iframe");
  nif.width = 850;
  nif.height = 500;
  nif.src = "http://www.google.de";
  nif.appendChild( document.createTextNode("no iframe support") );
  document.body.appendChild(nif);
};
</script>
</head>
<body>
<h1>IFRAME</h1>
</body>
</html>

Wouldn't it be easier to have the client fetch the Google page?

<html>
<head>
<script>
window.onload = function () {
  var nif = document.createElement("iframe");
  nif.width = 850;
  nif.height = 500;
  nif.src = "http://www.google.de";
  nif.appendChild( document.createTextNode("no iframe support") );
  document.body.appendChild(nif);
};
</script>
</head>
<body>
<h1>IFRAME</h1>
</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文