调用api.weixin.qq.com 提示证书错误是哪里出了问题?
发布于 4 年前 作者 lixue 2809 次浏览 来自 官方Issues

程序调用https://api.weixin.qq.com/sns/jscode2session 时会偶尔出现SSL错误,

主要是每调用5次左右 有2次就会出现这个错误,实在难受

using (HttpClient client = new HttpClient())
{
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(ContentType));
    client.DefaultRequestHeaders.AcceptCharset.Add(new StringWithQualityHeaderValue(Charset));
    client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36");
    client.DefaultRequestHeaders.Add("Timeout", Timeout.ToString());
    client.DefaultRequestHeaders.Add("KeepAlive", "true");
    //client.DefaultRequestHeaders.Date = DateTimeOffset.Now.AddHours(8);
    DebugLog.WriteLine("HTTP GET请求", url);
    var response = client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).Result;
    response.EnsureSuccessStatusCode();
                
    string result = response.Content.ReadAsStringAsync().Result;
    
    DebugLog.WriteLine("HTTP GET请求结束", result);
    return result;
}
Apr 16 14:00:41  ***-API[29810]:  ---> System.Net.Http.HttpRequestException: An error occurred while sending the request.
Apr 16 14:00:41  ***-API[29810]:  ---> System.Net.Http.CurlException: SSL connect error
Apr 16 14:00:41  ***-API[29810]:    at System.Net.Http.CurlHandler.ThrowIfCURLEError(CURLcode error)
Apr 16 14:00:41  ***-API[29810]:    at System.Net.Http.CurlHandler.MultiAgent.FinishRequest(StrongToWeakReference`1 easyWrapper, CURLcode messageResult)
Apr 16 14:00:41  ***-API[29810]:    --- End of inner exception stack trace ---

服务器在印度地区

2 回复

换其他证书试试。

换国内服务器吧

回到顶部