Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Node.js http.get_Javascript_Node.js_Proxy - Fatal编程技术网

Javascript Node.js http.get

Javascript Node.js http.get,javascript,node.js,proxy,Javascript,Node.js,Proxy,我有以下代码请求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('d

我有以下代码请求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?

最简单的解决方案是添加到html中。最好是在头部,所以在“”上用字符串替换,在“”中替换为“”

让客户端获取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>

window.onload=函数(){
var nif=document.createElement(“iframe”);
nif.width=850;
高度=500;
nif.src=”http://www.google.de";
appendChild(document.createTextNode(“无iframe支持”);
document.body.appendChild(nif);
};
IFRAME

PS。您可能还必须剥离JS,因为AJAX无法跨源工作。嗯,我以前从未见过。。。。听起来很合理,我要试一试,谢谢;)哥们,你又救了我一个星期,让我想用头撞显示器。谢谢你,万分感谢,万分欢迎。我想你的班长会很高兴:-)啊,对不起,我没有提到我是在服务器端通过Node js发出请求的。当然,我注意到了;我只是不明白为什么在客户端更容易。嗯,可能有一个原因。。。只是想不出它可能是什么。事实上,我现在知道你的解决方案是如何可行的了。我也要试一试。很好。:)当然,您可以对IFRAME进行硬编码,使其更加容易-如果问题的约束允许的话。