简体   繁体   中英

Phantomjs browser does not support CORS request on webpage

I want to take an html snapshot of my angularjs SPA. Angular application is getting data from tomcat server on another domain. SPA can successfully get data if on chrome browser, but get following error when inside phantomjs browser.

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 app is served using a nodejs server, which call phantom js to take HTML snapshot, if the url has ?_escaped_fragment_ in it. Server is deployed using apache ofbiz which uses tomcat internally. I have used default cors filter provided by Tomcat to support CORS on server side (and it works on chrome and firefox atleast).

I solved the issue. The problem was no with CORS request but with SSL handshake error.

For solution refer to this link : PhantomJs failling to open HTTPS sites

Use of phantomjs --ignore-ssl-errors=yes [phantomOptions] script.js [scriptOptions] solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM