Node.js http.get
我有以下代码,用于请求 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的解决方案是添加
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/">'
让客户端获取 Google 页面不是更容易吗?
Wouldn't it be easier to have the client fetch the Google page?