Unity使用https请求握手失败的处理方案
Unity使用https请求握手失败的处理方案
Handshake failed UNITYTLS_INTERNALS解决方案
var handler = new HttpClientHandler();//需要加这句 handler.ClientCertificateOptions = ClientCertificateOption.Manual;//需要加这句 using (HttpClient httpClient = new HttpClient(handler))//httpClient里带handler参数 { ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);//这里调用的是下面那个方法 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;//这句也要加 var content = new MultipartFormDataContent(); //var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); content.Headers.Add("ContentType", "multipart/form-data");//声明头部 content.Add(new StringContent("1"), "a"); httpClient.DefaultRequestHeaders.Add("Method", "Post"); HttpResponseMessage response = await httpClient.PostAsync("https://127.0.0.1:5555/api/WeatherForecast/GameTest", content);//Debug.Log("状态码0:" + response.StatusCode); response.EnsureSuccessStatusCode(); //Debug.Log("状态码1:" + response.StatusCode); string responseBody = await response.Content.ReadAsStringAsync(); Debug.Log("这里是.net core web api测试:" + responseBody); }
private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; //总是接受 }
小时候我把老婆种到地下,长大了我能收获一大堆老婆!
我是威少,我是一名Unity游戏的主程,我为自己带盐,希望此文能给您一点点微不足道的帮助,祝你成功!