赞
踩
注意:本文针对HTTPS在Unity出现的问题
错误码:
Error getting response stream (Write: The authentication or decryption has failed.): Send Failure
翻译:获取响应流错误(写入:身份验证或解密失败):发送失败
因为最近项目涉密。。所以甲方后台使用了 Https的通道。。。
天真的我觉得就是get嘛。。。
然而并不知道在unity里面 这种是要设置某些东西的!!!!!!
一顿胃疼。。。无知带来的后果啊
解决方法:
在发送任何请求前先加上如下代码:
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
private void Start()
{
ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;
}
public bool MyRemoteCertificateValidationCallback(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
bool isOk = true;
// If there are errors in the certificate chain,
// look at each error to determine the cause.
if (sslPolicyErrors != SslPolicyErrors.None)
{
for (int i = 0; i < chain.ChainStatus.Length; i++)
{
if (chain.ChainStatus[i].Status == X509ChainStatusFlags.RevocationStatusUnknown)
{
continue;
}
chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0);
chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
bool chainIsValid = chain.Build((X509Certificate2)certificate);
if (!chainIsValid)
{
isOk = false;
break;
}
}
}
return isOk;
}
我也不懂为啥。。。反正好了
感谢 Stack Overflow 的大佬
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。