Unity IOS 应用无法使用 UnityWebRequest 调用自签名证书 HTTPS
Unity IOS app can't use UnityWebRequest to call self signed certificate HTTPS
我使用了 window 和 android 都可以调用自签名证书 HTTPS,但是 ios 不能(无法完成 SSL 连接)。任何设置或编码都可以解决它吗?
public 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);
}
}
}
}
public class WebRequestCert : UnityEngine.Networking.CertificateHandler {
protected override bool ValidateCertificate(byte[] certificateData) {
//return base.ValidateCertificate(certificateData);
return true;
//return false;
}
}
有人问过类似的问题 。看起来您必须在 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>
我使用了 window 和 android 都可以调用自签名证书 HTTPS,但是 ios 不能(无法完成 SSL 连接)。任何设置或编码都可以解决它吗?
public 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);
}
}
}
}
public class WebRequestCert : UnityEngine.Networking.CertificateHandler {
protected override bool ValidateCertificate(byte[] certificateData) {
//return base.ValidateCertificate(certificateData);
return true;
//return false;
}
}
有人问过类似的问题
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>just-an-example.com</key>
<string></string>
</dict>
</dict>