我想拍摄我的 angularjs SPA 的 html 快照。 Angular 应用程序正在从另一个域上的 tomcat 服务器获取数据。 SPA在chrome浏览器中可以成功获取数据,但是在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 快照。服务器使用 apache ofbiz 部署,内部使用 tomcat。我使用了 Tomcat 提供的默认 cors 过滤器来支持服务器端的 CORS(它至少适用于 chrome 和 firefox)。
最佳答案
我解决了这个问题。问题不在于 CORS 请求,而在于 SSL 握手错误。
有关解决方案,请参阅此链接:PhantomJs failling to open HTTPS sites
使用 phantomjs --ignore-ssl-errors=yes [phantomOptions] script.js [scriptOptions]
解决了这个问题。
关于javascript - Phantomjs 浏览器不支持网页上的 CORS 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33638469/