如何在ionic3 http中为特定证书(iOS和Android)启用SSL固定?

时间:2018-12-05 16:12:14

标签: https ionic3 ssl-certificate ionic-native ionic-native-http

我们正在开发基于离子框架的应用程序。在调用基于HTTP的API时,它可以正常工作,但是在访问基于HTTPs的API时,它会失败,因为它需要证书验证。

我不确定如何使用ionic 3 http插件来启用相同功能。

我已经尝试过使用iOS本机代码,并且API在那里可以使用证书进行启用固定。 -iOS Objective-C应用:代码here

NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"myCompany" ofType:@"cer"]; NSData *myCertData = [NSData dataWithContentsOfFile:cerPath];

离子应用程序中的几行代码:

import { HTTP } from '@ionic-native/http';
constructor(private _mHTTP: HTTP) {
    this.platform.ready().then(() => {
        this._mHTTP.setSSLCertMode('nocheck');
    }

    public getAPIPromise<T>(path: string, headers: any): Promise<T>{
        debugger
        this._mHTTP.setSSLCertMode('nocheck');

        return this._mHTTP.get(path, {}, headers).then((d) => {
            let t: T = this.convertReturn<T>(d.data);
            return t;
        });
    }

}

如何在适用于Android和iOS的纯ionic3代码中实现相同的目标。

任何提示或准则都会有所帮助。谢谢。

0 个答案:

没有答案