J'ai une API d'accès problème, url retourne toujours IP externe:http://192.168.**.**:8100
API d'appel ionique avec Proxy retourne toujours 404
Mon API est hébergé sur le serveur IIS local comme celui-ci IP 192.168.**.**:3000
Quand je debug projet sur Android Emulator je vois sur la console de débogage:
Proxy added:/api => http://192.168.**.**:3000/
J'utilise cette méthode d'accès à l'API. Mais mon URL retourne toujours 192.168.**.**:8100/api/Configurations/GetAppConfiguration
alors j'obtiens une erreur 404 car mon adresse IP de l'API utilise le port 3000.
J'ai ajouté config.xml permettre la navigation href mon URL d'API http://192.168.**.**:3000
mais cela n'a pas fonctionné.
Quel est le problème? Qu'est-ce que je rate ?
Merci vous pour vous aider ...
GetMethod
getPosts(): Observable<any[]> {
debugger;
return this.http.get("api/Configurations/GetAppConfiguration")
.map(this.parseData)
.catch(this.handleError);
}
Ionic.config.json
{
"name": "myApp",
"app_id": "",
"type": "ionic-angular",
"integrations": {
"cordova": {}
},
"proxies": [
{
"path": "/api",
"proxyUrl": "http://192.168.** .** :3000"
}
]
}
launch.json
"name": "Run Android on emulator",
"type": "cordova",
"request": "launch",
"platform": "android",
"target": "emulator",
"port": 9222,
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"ionicLiveReload": true,
"devServerTimeout": 120000
Config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.ionic.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>MyApp</name>
<description>An awesome Ionic/Cordova app.</description>
<author email="[email protected]" href="http://ionicframework.com/">Ionic Framework Team</author>
<content original-src="index.html" src="http://192.168.**.**:8100" />
<access origin="*" />
<allow-navigation href="http://ionic.local/*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<preference name="webviewbounce" value="false" />
<preference name="UIWebViewBounce" value="false" />
<preference name="DisallowOverscroll" value="true" />
<preference name="android-minSdkVersion" value="16" />
<preference name="BackupWebStorage" value="none" />
<preference name="SplashScreen" value="none" />
<platform name="android">
<allow-intent href="market:*" />
<icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<icon height="57" src="resources/ios/icon/icon.png" width="57" />
</platform>
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="SplashScreenDelay" value="3000" />
<allow-navigation href="http://192.168. ** . ** :8101" />
<allow-navigation href="http://192.168. ** . ** :8100" />
<engine name="android" spec="^6.2.3" />
<plugin name="cordova-plugin-device" spec="^1.1.6" />
<plugin name="cordova-plugin-network-information" spec="^1.3.3" />
<plugin name="cordova-plugin-screensize" spec="^1.3.1" />
<plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
<plugin name="cordova-plugin-statusbar" spec="^2.2.3" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.2" />
<plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
</widget>
Pourquoi ne pas utiliser simplement 'retourner this.http.get (" http: //192.168.xx: 3000/Configurations/GetAppConfiguration ")' – Ivaro18
si j'utilise directement, j'obtiens une erreur Réponse avec statut: 0 pour URL: null " –
Vous déclarez votre proxy sur'/api' mais vous appelez '/ Confiruation' sans utiliser votre proxy . Essayez '/ api/Configuration' – Ivaro18