Keine redirects

This commit is contained in:
2026-07-29 09:50:08 +02:00
parent 9b491c7669
commit 427641fe9f
3 changed files with 17 additions and 6 deletions

View File

@@ -437,9 +437,9 @@
<add key="SendMailModuleGkvSender" value="noreply@bewoplaner.de" />
<add key="SendMailModuleGkvReceiver" value="dakota.exchange@ownsoft.de" />
<add key="OllamaUrl" value="https://ai2.ownsoft.de" />
<add key="Ollama2Url" value="https://ai3.ownsoft.de" />
<add key="AiPromptsUrl" value="https://test2.evplaner.de" />
<add key="OllamaUrl" value="https://ai2.ownsoft.de/" />
<add key="Ollama2Url" value="https://ai3.ownsoft.de/" />
<add key="AiPromptsUrl" value="https://manage2.evplaner.de/" />
<add key="XRechnungApiUrl" value="https://test2.evplaner.de/xrg/" />
<add key="StoredFilesFolderPath" value="C:\BeWoPlaner\StoredFiles" />

View File

@@ -26,6 +26,7 @@ namespace BeWo.ServerUtils.ApiFacade
private ILog _logger;
public bool DirectConnect { get; private set; }
public bool AllowRedirect { get; private set; }
public string Base_Url { get; private set; }
public HttpMethod Method { get; set; } = HttpMethod.Get;
@@ -35,7 +36,7 @@ namespace BeWo.ServerUtils.ApiFacade
public Encoding Encoding { get; set; } = Encoding.UTF8;
public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(30);
public HttpClientFacade(string base_url, string api_key, bool directConntect = true)
public HttpClientFacade(string base_url, string api_key, bool directConntect = true, bool allow_redirect = false)
{
if (string.IsNullOrEmpty(base_url))
throw new ArgumentNullException("HttpClient: base_url is missing");
@@ -47,6 +48,7 @@ namespace BeWo.ServerUtils.ApiFacade
if (!string.IsNullOrWhiteSpace(api_key))
SetToken(api_key);
DirectConnect = directConntect;
AllowRedirect = allow_redirect;
_logger = LoggerUtils.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
}
@@ -126,7 +128,7 @@ namespace BeWo.ServerUtils.ApiFacade
return parse(() => (T)result, content, extractor);
}
private static bool ServerCertificateCustomValidation(HttpRequestMessage requestMessage, X509Certificate2 certificate, X509Chain chain, SslPolicyErrors sslErrors)
protected static bool ServerCertificateCustomValidation(HttpRequestMessage requestMessage, X509Certificate2 certificate, X509Chain chain, SslPolicyErrors sslErrors)
{
// It is possible to inspect the certificate provided by the server.
Console.WriteLine($"Requested URI: {requestMessage.RequestUri}");
@@ -146,6 +148,7 @@ namespace BeWo.ServerUtils.ApiFacade
{
ServerCertificateCustomValidationCallback = ServerCertificateCustomValidation,
SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls,
AllowAutoRedirect = AllowRedirect
};
using (var client = new HttpClient(handler) { Timeout = Timeout })

View File

@@ -1,4 +1,5 @@
using System.Net.Http;
using System.Security.Authentication;
using System.Text.Json;
using System.Threading.Tasks;
@@ -16,7 +17,14 @@ namespace BeWo.ServerUtils.ApiFacade
private protected override async Task<HttpResponseMessage> getResponseAsync(string method)
{
using (var client = new HttpClient { Timeout = Timeout })
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = ServerCertificateCustomValidation,
SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls,
AllowAutoRedirect = AllowRedirect
};
using (var client = new HttpClient(handler) { Timeout = Timeout })
{
var requestUri = BS.Shared.Core.Utilities.WebUtils.CombineUrl(Base_Url, method);