add method to post StreamContent

This commit is contained in:
tekh 2025-08-15 15:34:31 +02:00
parent 2877d62f95
commit aaaaf283ee

View File

@ -116,4 +116,31 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
};
}
}
public async Task<Response<TData, TError>> PostAsync<TData>(StreamContent content, string? route = null, object? queryParams = null, CancellationToken cancel = default)
where TData : class
{
route = AddQueryString(route, queryParams);
var res = await Http.PostAsync(route, content, cancel);
if (res.IsSuccessStatusCode)
{
return new()
{
Ok = true,
StatusCode = res.StatusCode
};
}
else
{
var error = await res.Content.ReadFromJsonAsync<TError>(_options.JsonSerializerOptions, cancel);
return new()
{
Ok = false,
StatusCode = res.StatusCode,
Error = error
};
}
}
}