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

Phantomjs browser does not support CORS request on webpage

我想拍摄 html 我的 angularjs SPA 的快照。 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")

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

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

解决方法参考这个link:

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