簡體   English   中英

離子Android模擬器問題

[英]Ionic Android Emulator issue

從我的應用程序中,我引用外部API來獲取數據。 在瀏覽器和內置版本上,一切正常,但在模擬器請求上被拒絕。 在實際的設備上運行就可以了。 對於調試,我需要在模擬器上進行測試,但出現此錯誤。 我檢查了所有可能的文章,但找不到解決方案。 這是我的配置

離子信息

Cordova CLI: 6.4.0
Ionic CLI Version: 2.1.4
Ionic App Lib Version: 2.1.2
OS: Distributor ID: Ubuntu Description: Ubuntu 15.10 
Node Version: v6.3.1

配置文件

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.freemusic372670" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>
        FreeMusic
    </name>
  <description>
        An Ionic Framework and Cordova project.
    </description>
  <author email="you@example.com" href="http://example.com.com/">
        Your Name Here
    </author>
  <access origin="*"/>
  <allow-intent href="*"/>
  <allow-navigation href="http://*/*"/>
  <allow-navigation href="https://*/*"/>
  <allow-navigation href="data:*"/>
  <allow-navigation href="http://10.11.11.127:8100"/>
  <allow-navigation href="http://10.11.11.127:8101"/>
  <allow-navigation href="http://192.168.42.87:8100"/>
  <content src="index.html"/>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="SplashScreenDelay" value="2000"/>
  <preference name="FadeSplashScreenDuration" value="2000"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <preference name="SplashScreen" value="screen"/>
  <feature name="StatusBar">
    <param name="ios-package" onload="true" value="CDVStatusBar"/>
  </feature>
  <plugin name="cordova-plugin-device" spec="~1.1.3"/>
  <plugin name="cordova-plugin-console" spec="~1.0.4"/>
  <plugin name="cordova-plugin-whitelist" spec="~1.3.0"/>
  <plugin name="cordova-plugin-splashscreen" spec="~4.0.0"/>
  <plugin name="cordova-plugin-statusbar" spec="~2.2.0"/>
  <plugin name="ionic-plugin-keyboard" spec="~2.2.1"/>
  <platform name="android">
    <icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
    <icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
    <icon src="resources/android/icon/drawable-hdpi-icon.png" density="hdpi"/>
    <icon src="resources/android/icon/drawable-xhdpi-icon.png" density="xhdpi"/>
    <icon src="resources/android/icon/drawable-xxhdpi-icon.png" density="xxhdpi"/>
    <icon src="resources/android/icon/drawable-xxxhdpi-icon.png" density="xxxhdpi"/>
    <splash src="resources/android/splash/drawable-land-ldpi-screen.png" density="land-ldpi"/>
    <splash src="resources/android/splash/drawable-land-mdpi-screen.png" density="land-mdpi"/>
    <splash src="resources/android/splash/drawable-land-hdpi-screen.png" density="land-hdpi"/>
    <splash src="resources/android/splash/drawable-land-xhdpi-screen.png" density="land-xhdpi"/>
    <splash src="resources/android/splash/drawable-land-xxhdpi-screen.png" density="land-xxhdpi"/>
    <splash src="resources/android/splash/drawable-land-xxxhdpi-screen.png" density="land-xxxhdpi"/>
    <splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/>
    <splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/>
    <splash src="resources/android/splash/drawable-port-hdpi-screen.png" density="port-hdpi"/>
    <splash src="resources/android/splash/drawable-port-xhdpi-screen.png" density="port-xhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxhdpi-screen.png" density="port-xxhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/>
  </platform>
</widget>

index.html中的META HEADER

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

插件

cordova-plugin-whitelist

錯誤

{"data":null,"status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://databrainz.com/api/search_api.cgi?qry=metallica&format=json&mh=50&where=mpl","headers":{"Accept":"application/json, text/plain, */*"}},"statusText":""}

LOGCAT錯誤

11-30 11:51:50.971 3179-3179/com.ionicframework.freemusic372670 D/SystemWebChromeClient: http://10.11.11.127:8100/#/tab/dash: Line 0 : XMLHttpRequest cannot load http://databrainz.com/api/search_api.cgi?qry=metallica&format=json&mh=50&where=mpl. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://10.11.11.127:8100' is therefore not allowed access.

您必須通過Web服務器啟用CORS 您的錯誤提到了這一點:

…No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://10.11.11.127:8100' is therefore not allowed access.…

暫無
暫無

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

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