diff --git a/src/OrchardCore/OrchardCore.ReCaptcha.Core/Services/ReCaptchaService.cs b/src/OrchardCore/OrchardCore.ReCaptcha.Core/Services/ReCaptchaService.cs index 737c7cf0dc9..c12142eeacf 100644 --- a/src/OrchardCore/OrchardCore.ReCaptcha.Core/Services/ReCaptchaService.cs +++ b/src/OrchardCore/OrchardCore.ReCaptcha.Core/Services/ReCaptchaService.cs @@ -27,8 +27,8 @@ public class ReCaptchaService private readonly IEnumerable _robotDetectors; private readonly IHttpContextAccessor _httpContextAccessor; private readonly ILogger _logger; + private readonly string _verifyHost; protected readonly IStringLocalizer S; - private HttpClient _httpClient; public ReCaptchaService( IHttpClientFactory httpClientFactory, @@ -40,6 +40,7 @@ public ReCaptchaService( { _httpClientFactory = httpClientFactory; _reCaptchaSettings = optionsAccessor.Value; + _verifyHost = $"{optionsAccessor.Value.ReCaptchaApiUri?.TrimEnd('/')}/siteverify"; _robotDetectors = robotDetectors; _httpContextAccessor = httpContextAccessor; _logger = logger; @@ -124,8 +125,8 @@ private async Task VerifyAsync(string responseToken) { "response", responseToken } }); - _httpClient ??= _httpClientFactory.CreateClient(nameof(ReCaptchaService)); - var response = await _httpClient.PostAsync($"{_reCaptchaSettings.ReCaptchaApiUri.TrimEnd('/')}/siteverify", content); + var httpClient = _httpClientFactory.CreateClient(nameof(ReCaptchaService)); + var response = await httpClient.PostAsync(_verifyHost, content); response.EnsureSuccessStatusCode(); var result = await response.Content.ReadFromJsonAsync(_jsonSerializerOptions);