string url = $"https://api.weixin.qq.com/sns/oauth2/access_token?appid={appID}&secret={appSecret}&code={code}&grant_type=authorization_code";
var client = _httpClientFactory.CreateClient();
var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, url));
if (!response.IsSuccessStatusCode) return null;
var result = await response.Content.ReadAsStringAsync();
OauthTokenResult accessToken = JsonConvert.DeserializeObject<OauthTokenResult>(result);
_logger.LogWrite($"獲取授權AccessToken:{result}");
return accessToken;2020/02/29 20:16:48.081|ERROR|=======================================================================
用戶IP:119.44.61.188
發生例外頁:https://api.barendao.com/api/AccessToken/WeChat
錯誤源:System.Net.Http
例外資訊:The SSL connection could not be established, see inner exception.
例外堆疊:
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
at Barendao.WeChat.OAuths.OAuthHandler.GetOauthTokenAsync(String appID, String appSecret, String code) in E:\canxinSoft\PrintingNet\src\V2\Utility\Barendao.WeChat\OAuths\OAuthHandler.cs:line 33
at Barendao.WebApi.Controllers.AccessTokenController.Login(WeChatLoginModel model) in E:\canxinSoft\PrintingNet\src\V2\Barendao.WebApi\Controllers\AccessTokenController.cs:line 56
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
=======================================================================
uj5u.com熱心網友回復:
例外資訊讓你看具體的InnerException。
你還可以提供其他資訊,
比如netcore的版本,
比如在Windows機器上除錯是否正常,
比如在Centos上是否可以正常curl https://api.weixin.qq.com/sns/oauth2
等等等等...
有一種可能是Centos7的證書容器,沒有設定正常,沒有信任api.weixin.qq.com所用證書的發行方。
另一種可能是netcore的配置,導致HttpClient沒有正確使用證書容器。
uj5u.com熱心網友回復:
多謝大佬,我稍微補充一下
注意的系統時間是否同步,時區對不對
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/66430.html
標籤:C#
上一篇:求大神幫忙!
