【问题标题】:Unity IOS app can't use UnityWebRequest to call self signed certificate HTTPSUnity IOS 应用无法使用 UnityWebRequest 调用自签名证书 HTTPS
【发布时间】:2020-10-19 04:49:24
【问题描述】:

我用window和android都可以调用自签名证书HTTPS,但ios不行(无法完成SSL连接)。任何设置或编码都可以解决它?

公共 IEnumerator SetGroupID(int id) { 字符串 url = AppConfig.APIDomain + "/Game/setGroupID/" + id;

    Debug.Log("Check color URL : " + url);
    using (UnityWebRequest webRequest = UnityWebRequest.Get(url)) {
        // Request and wait for the desired page.
        webRequest.certificateHandler = new WebRequestCert();
        
        yield return webRequest.SendWebRequest();
        string[] pages = url.Split('/');
        int page = pages.Length - 1;

        if (webRequest.isNetworkError) {
            Debug.Log(pages[page] + ": Error: " + webRequest.error);
            GameMainMenuUI.Instance.OhError(webRequest.error);
        }
        else {
            try {
                Debug.Log(webRequest.downloadHandler.text);
            }
            catch (Exception e) {
                GameMainMenuUI.Instance.OhError("Get Init Data Failed : "+e);
            }
        }
    }

}

公共类 WebRequestCert : UnityEngine.Networking.CertificateHandler {

protected override bool ValidateCertificate(byte[] certificateData) {
    //return base.ValidateCertificate(certificateData);
    return true;

    //return false;
}

}

【问题讨论】:

    标签: ios unity3d ssl unitywebrequest


    【解决方案1】:

    here 提出了类似的问题。看起来您必须在 Info.plist 文件中指定您希望允许 iOS 应用程序的“不安全”http 连接。

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>just-an-example.com</key>
            <string></string>
        </dict>
    </dict>
    

    【讨论】:

    • 但我正在使用自签名 SSL 连接 HTTPS
    • @sopapok 我建议 iOS 不接受自签名证书
    • 所以苹果不允许开发者用自签名 SSL 连接 HTTPS,但是 HTTP 可以吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-10
    • 2018-06-02
    • 1970-01-01
    • 2014-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多