本文介绍了JavaFX WebView禁用同源策略(允许跨域请求)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个JavaFX应用程序,它主要是一个美化的网页。它是一个桌面应用程序(它没有嵌入到一个网页),它有一个主视图的Web视图。该应用程序本身仅用于使用Bluecove访问蓝牙设备,因为在网络浏览器上无法直接使用JavaScript。

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.

概念验证可以正常工作从JavaScript调用JavaScript代码,反之亦然),但我有一个额外的要求从JavaScript内调用任意的Web服务/ API,但这违反了相同的源策略(类似于Android上的这一点:)。这是可能在JavaFX吗?任何提示?

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?

PS:我使用的是JavaFX 2.2。

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

推荐答案

p>基本上,javaFx有一个问题,加上CORS - 。假设您使用的Web服务启用了CORS,您可以尝试以下方法:

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)

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


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

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

希望它会帮助你

这篇关于JavaFX WebView禁用同源策略(允许跨域请求)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 18:28