forked from sim0n00ps/OF-DL
OFDL: Enabled setting HttpMethod and Body
This commit is contained in:
parent
8eaa14ae03
commit
8d5cc39722
@ -2755,11 +2755,11 @@ public class ApiService(IAuthService authService, IConfigService configService,
|
||||
|
||||
|
||||
protected async Task<string?> BuildHeaderAndExecuteRequests(Dictionary<string, string> getParams, string endpoint,
|
||||
HttpClient client)
|
||||
HttpClient client, HttpMethod? method = null, object? reqBody = null)
|
||||
{
|
||||
Log.Debug("Calling BuildHeaderAndExecuteRequests");
|
||||
|
||||
HttpRequestMessage request = await BuildHttpRequestMessage(getParams, endpoint, method);
|
||||
HttpRequestMessage request = await BuildHttpRequestMessage(getParams, endpoint, method, reqBody);
|
||||
using HttpResponseMessage response = await client.SendAsync(request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
string body = await response.Content.ReadAsStringAsync();
|
||||
@ -2771,15 +2771,21 @@ public class ApiService(IAuthService authService, IConfigService configService,
|
||||
|
||||
|
||||
protected Task<HttpRequestMessage> BuildHttpRequestMessage(Dictionary<string, string> getParams,
|
||||
string endpoint)
|
||||
string endpoint, HttpMethod? method = null, object? reqBody = null)
|
||||
{
|
||||
Log.Debug("Calling BuildHttpRequestMessage");
|
||||
|
||||
string queryParams = "?" + string.Join("&", getParams.Select(kvp => $"{kvp.Key}={kvp.Value}"));
|
||||
string queryParams = "";
|
||||
|
||||
if (getParams.Count != 0)
|
||||
queryParams = "?" + string.Join("&", getParams.Select(kvp => $"{kvp.Key}={kvp.Value}"));
|
||||
|
||||
Dictionary<string, string> headers = GetDynamicHeaders($"/api2/v2{endpoint}", queryParams);
|
||||
|
||||
HttpRequestMessage request = new(HttpMethod.Get, $"{Constants.ApiUrl}{endpoint}{queryParams}");
|
||||
HttpRequestMessage request = new(method ?? HttpMethod.Get, $"{Constants.ApiUrl}{endpoint}{queryParams}");
|
||||
|
||||
if ((method == HttpMethod.Post || method == HttpMethod.Put || method == HttpMethod.Patch) && reqBody != null)
|
||||
request.Content = new StringContent(JsonConvert.SerializeObject(reqBody, s_mJsonSerializerSettings), Encoding.UTF8, "application/json");
|
||||
|
||||
Log.Debug($"Full request URL: {Constants.ApiUrl}{endpoint}{queryParams}");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user