幻象节点模块无法加载外部资源 [英] Phantom-node module unable to load external resources

查看:90
本文介绍了幻象节点模块无法加载外部资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用nodejs服务器,该服务器将发布的html渲染为pdf,png或jpg. ( https://github.com/svenhornberg/pagetox (server.js)如果您想尝试它)

i'm working on a nodejs server which renders posted html to pdf,png or jpg. ( https://github.com/svenhornberg/pagetox (server.js) if you want to try it)

它确实工作得很好,可以渲染复杂的网站,但是直到我要加载简单图像的那一点.例如,我正在向服务器发送以下代码:

It is working really good, renders complex sites but only to that point that i want do load a simple image. For example i am sending following code to my server:

<!doctype html>
<html>
<head>
  <title>logo</title>
</head>
<body>
  <img alt="logo" src="http://upload.wikimedia.org/wikipedia/commons/d/de/Wikipedia_Logo_1.0.png">
</body>
</html>

代码应该没问题. 但是呈现的响应图像不包含徽标图像. 如phantomjs文档( http://phantomjs.org/api/webpage/property /settings.html )localToRemoteUrlAccessEnabled设置为false,因此将其设置为true,如phantom-node( https://github.com/sgentle/phantomjs-node/):

The Code should be okay. But the rendered response image does not contain the logo image. As said in the phantomjs documentation (http://phantomjs.org/api/webpage/property/settings.html) localToRemoteUrlAccessEnabled is set to false, so set it to true like said in the documentation of phantom-node (https://github.com/sgentle/phantomjs-node/):

  page.set('settings.localToRemoteUrlAccessEnabled', true);
  page.set('settings.loadImages', true);

为了证明它设置为true,我称它为getter,它返回true

to prove it is set to true, i called a getter which returns true

  page.get('settings.localToRemoteUrlAccessEnabled', function(data) { console.log(data);});

我在Linux上将节点v0.10.26与phantomjs-node(0.6.1)和phantomjs(1.9.7)一起使用

i'm using node v0.10.26 with phantomjs-node (0.6.1), phantomjs(1.9.7) on linux

现在的问题是,有人看到错误了吗?或可以给我提示我做错了什么.还是任何其他可能性,为什么phantomjs/phtanom-node不加载任何外部图像

我正在使用render方法生成png,jpg或pdf文件.我正在将Evaluate函数中的方法作为回调调用,因此应该完全加载该网站. (完整的代码位于 https://github.com/svenhornberg/pagetox/blob/master/server.js )

I am using the render method to generate the png, jpg or pdf file. I am calling the method inside the evaluate function as a callback, so the site should be loaded completely. (the full code is at https://github.com/svenhornberg/pagetox/blob/master/server.js)

Edit1:我没有代理,它可能阻止了请求.

I'm not behind a proxy, which maybe blocks the requests.

推荐答案

您要设置的是

page.set('settings.webSecurityEnabled', false);

启用跨域请求.另一个选项localToRemoteUrlAccessEnabled不会影响您的情况,因为您没有使用file:资源,而是覆盖了about:blank.

Which enables cross domain requests. The other option localToRemoteUrlAccessEnabled does not affect your case because you don't use file: resources but you rather overwrite about:blank.

其他问题可能与SSL/TLS有关.请参阅我的答案此处以获取更多帮助.

Other issues might be SSL/TLS related. See my answer here for more help.

这篇关于幻象节点模块无法加载外部资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆