Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
844 views
in Technique[技术] by (71.8m points)

javascript - JavaFX WebView disable Same origin policy (allow cross domain requests)

I'm developing a JavaFX application that is mostly a glorified web page. It's a desktop application (it's no embedded into a web page) and it has a Web View for the main UI. The application itself serves the sole purpose of accessing Bluetooth devices using Bluecove because that's not possible directly with JavaScript on a web browser.

The proof of concept works ok (I was able to call JavaScript code from Java and vice-versa) but I have one extra requirement of calling arbitrary web services/API from within JavaScript but this violates the same origin policy (similar to this on Android: Allow remote ajax calls in an Android Webview + jquery mobile). Is this possible on JavaFX? Any tips?

P.S.: I'm using JavaFX 2.2.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Basically, javaFx has the issue which is coupled with CORS - https://javafx-jira.kenai.com/browse/RT-35868. Assuming that web services which you are using, have CORS enabled you can try the following approach:

  • System.setProperty("sun.net.http.allowRestrictedHeaders", "true")

OR

  • java -Dsun.net.http.allowRestrictedHeaders=true <your main class here>

Hope it will help you


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...