Phantomjs浏览器不支持网页上的CORS请求

时间:2015-11-10 19:58:17

标签: javascript angularjs node.js seo phantomjs

我想拍摄我的angularjs SPA的html快照。 Angular应用程序从另一个域的tomcat服务器获取数据。如果在Chrome浏览器上,SPA可以成功获取数据,但在phantomjs浏览器中时会出现以下错误。

ERROR{"data":null,"status":0,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"https://localhost:8443/gomovie/control/getHomeData","headers":{"Content-Type":"application/json","Accept":"application/json, text/plain, */*"},"data":""},"statusText":""} (from line #undefined in "undefined")

使用nodejs服务器提供Angular应用程序,如果url中包含?_escaped_fragment_,则调用phantom js来获取HTML快照。使用内部使用tomcat的apache ofbiz部署服务器。我使用了Tomcat提供的默认cors过滤器来支持服务器端的CORS(并且它至少适用于chrome和firefox)。

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。问题不在于CORS请求,而在于SSL握手错误。

有关解决方案,请参阅此链接:PhantomJs failling to open HTTPS sites

使用phantomjs --ignore-ssl-errors=yes [phantomOptions] script.js [scriptOptions]解决了这个问题。