mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
@@ -73,23 +73,30 @@ namespace MaaWpfGui.Services.Web
|
||||
|
||||
private static async Task<HttpResponseMessage?> TryPostAsync(string targetUrl, HttpContent content, Dictionary<string, string> headers)
|
||||
{
|
||||
int currentBackoff = InitialBackoffMs;
|
||||
for (int attempt = 1; attempt <= MaxRetryPerDomain; attempt++)
|
||||
try
|
||||
{
|
||||
var response = await Instances.HttpService.PostAsync(new(targetUrl), content, headers);
|
||||
|
||||
switch ((int)response.StatusCode)
|
||||
int currentBackoff = InitialBackoffMs;
|
||||
for (int attempt = 1; attempt <= MaxRetryPerDomain; attempt++)
|
||||
{
|
||||
case 200:
|
||||
return response;
|
||||
case >= 500 and < 600:
|
||||
await Task.Delay(currentBackoff);
|
||||
currentBackoff = (int)(currentBackoff * 1.5);
|
||||
continue;
|
||||
default:
|
||||
return response;
|
||||
var response = await Instances.HttpService.PostAsync(new(targetUrl), content, headers);
|
||||
|
||||
switch ((int)response.StatusCode)
|
||||
{
|
||||
case 200:
|
||||
return response;
|
||||
case >= 500 and < 600:
|
||||
await Task.Delay(currentBackoff);
|
||||
currentBackoff = (int)(currentBackoff * 1.5);
|
||||
continue;
|
||||
default:
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, "Error during HTTP POST request to {TargetUrl}", targetUrl);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user