2017-10-09 76 views
1

我有一个问题访问API,URL总是返回外部IP:http://192.168.**.**:8100离子调用API与代理总是返回404

我的API是本地IIS服务器上托管这样的IP 192.168.**.**:3000

当我调试运行在Android模拟器项目中,我看到调试控制台上:

Proxy added:/api => http://192.168.**.**:3000/

我用这个方法访问api。但我的网址总是返回 192.168.**.**:8100/api/Configurations/GetAppConfiguration,所以我得到一个错误404,因为我的API IP地址使用3000端口。

我添加config.xml允许导航href我的API url http://192.168.**.**:3000但它没有工作。

什么问题?我错过了什么?

感谢您的帮助......

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> 
+0

你为什么不只是使用'返回this.http.get(“HTTP://192.168.xx: 3000/Configurations/GetAppConfiguration“)' – Ivaro18

+0

如果直接使用,我得到一个错误状态的响应:0对于URL:null” –

+0

你声明'/ api'上的代理,但是你调用'/ Confiruation',因此不使用你的代理。试试'/ api/Configuration' – Ivaro18

回答

2

我解决了这个问题

新增ionic.config.json文件我的代理设置这样

"proxies": [ 
     { 
      "path": "*/apibase", 
      "proxyUrl": "http://192.168. ** . **:3000" 
     } 
    ] 

改变配置。 xml文件并添加新的配置属性

<allow-navigation href="http://*/*" /> 
<allow-intent href="https://*/*" /> 

使用GET方法这样

getPosts(): Observable<any[]> {   
return this.http.get("apibase/api/Configurations/GetAppConfiguration") 
    .map(this.parseData) 
    .catch(this.handleError); 

}