【发布时间】:2018-10-29 19:26:06
【问题描述】:
我知道HTTPS request fails only on iOS, Ionic 2 之前有人问过这个问题,但这些答案对我不起作用。
我已经在 ios xcode10 项目的 [myproject]-info.plist 文件中进行了以下设置
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
我的项目中没有安装 wkwebview 插件here,而是在我的项目中安装了 ionic-webview-plug。
端点是托管在 Windows 服务器中的 MVC 控制器操作方法。我无法像在 Android 测试中那样使用 chrome://inspect 从 Windows 调试 IOS 应用程序。虽然 App 能够访问图片等其他静态链接,但此 Web 服务调用失败。
下面的 Angular 代码是如何使用 HttpClient 进行 Web 服务调用的
var oDat = {
uuid: uuid
};
let headers = new HttpHeaders();
headers = headers.set(‘Content-Type’, ‘application/json; charset=utf-8’);
return this.http.post(this.apiUrl23, JSON.stringify(oDat), {headers: headers}).pipe(
map(this.extractData),
catchError(this.handleError)
);
以下是从页面触发的此类订阅者代码
this.horoService.getPlan(this.device.uuid)
.subscribe(res => {
this.info2 = '';
let pln: Plan = { uuid: res['uuid'], name: res['name'], credits: res['credits'], dobs: res['dobs'] };
this.plan = pln;
if(res['name'] == 'xxx.xxx.xxx.xxx'){
this.showSU = true;
this.showCR = false;
this.showASU = false;
} else if(Number(res['credits']) == 0) {
this.showSU = false;
this.showCR = true;
this.showASU = false;
} else {
this.showSU = true;
this.showCR = false;
this.showASU = true;
}
}, (err) => {
this.showSU = false;
this.showCR = false;
this.showASU = false;
this.info2 = JSON.stringify(err);
});
以下是我项目中使用的 Cordova 版本
Ionic:
ionic (Ionic CLI) : 4.2.1 (C:\Users\Hamsini\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.0
Cordova:
cordova (Cordova CLI) : 8.0.0
Cordova Platforms : android 6.3.0, ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 1.2.1, (and 12 other plugins)
在 xCode10 上构建并在 ipad 版本 9.3.5 上测试
你猜到了吗?
UPDATE-30/10 当我使用 ionic serve 运行时,我可以看到 HTTPResponse 正确返回,但是在 .subscribe (err) 处理程序中它显示 Unknown URL, Unknown error
【问题讨论】:
-
你遇到了什么错误?
-
实际上通信没有问题,因为我可以看到 HTTPResponse 在从 ionic serve 测试时返回,而 (err) 显示为未知 URL,未知错误