服务器今天把http协议换成https以后,连接导致出现Unable to complete SSL connection。相同的代码访问百度是OK的。由于我们这边服务器的SSL证书是自己生成的,没有经过网络认证导致的。后面想通过不验证SSL,结果成功了。。。详细代码在下方。
UnityWebRequest request = UnityWebRequest.Post(url, mParam.ToString());
request.SetRequestHeader("Content-Type", "application/json");
request.SetRequestHeader("Accept", "application/json");
request.certificateHandler =new BypassCertificate() ;
yield return request.SendWebRequest();
if (request.isNetworkError)
{
callBack?.Invoke(0, request.downloadHandler.text);
}
else
{
callBack?.Invoke(1, request.downloadHandler.text);
}
主要还是标红的那句,BypassCertificate的用法如下:
public class BypassCertificate : CertificateHandler
{
protected override bool ValidateCertificate(byte[] certificateData)
{
return true;
}
}
搞定!!!