簡體   English   中英

在android web視圖中,Access-Control-Allow-Origin.:1不允許使用null?

[英]Origin null is not allowed by Access-Control-Allow-Origin.:1 in android web view?

我收到此錯誤:

XMLHttpRequest cannot load http://192.168.1.33:8080/ws/target. Origin null is not allowed by Access-Control-Allow-Origin.:1

當我嘗試在webview上加載html頁面時。我輸入腳本標簽。

<script src="http://192.168.1.33:8080/target/target-script-min.js#anonymous"></script>

實際上當我嘗試在weinre上調試我的代碼時出現此錯誤。 你能告訴我如何刪除這個錯誤嗎?

有沒有辦法刪除此錯誤? 但是當我制作phonegap項目並使用相同的導入腳本行加載相同的HTML時。

<script src="http://192.168.1.33:8080/target/target-script-min.js#anonymous"></script>

用這條線

我可以在winre上調試我的文件。

你可以告訴我在加載webview時如何刪除此錯誤嗎?

由於瀏覽器中的CORS策略,問題正在發生。 為了消除錯誤,您通常必須將更改服務器端更改為您正在使用的任何服務器。 你必須添加標題:

Access-Control-Allow-Origin: *

有關如何針對特定后端框架執行此操作的詳細信息,請參閱此處

也就是說,因為你使用cordova,你也可以像這樣覆蓋瀏覽器的行為:

if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
    wv.getSettings().setAllowUniversalAccessFromFileURLs(true);
}

如果您使用的是webview。 如果你不想直接搞亂webview,你也可以設置

<access uri="*" subdomains="true" />

在你的res/xml/cordova.xml 有關詳細信息,請參閱此處http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM