From 94a495466d30621f7e437bb902aea007e9b73929 Mon Sep 17 00:00:00 2001 From: dawkaka Date: Mon, 2 Sep 2024 18:44:12 +0000 Subject: [PATCH] handle form-data --- ApiToolKit.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ApiToolKit.cs b/ApiToolKit.cs index bdec8f6..f19f2e7 100644 --- a/ApiToolKit.cs +++ b/ApiToolKit.cs @@ -97,6 +97,18 @@ public async Task InvokeAsync(HttpContext context) requestBody = JsonConvert.SerializeObject(dictionary); } + else if (contentType != null && contentType.StartsWith("multipart/form-data")) + { + try + { + var form = await context.Request.ReadFormAsync(); + var formData = form.ToDictionary(x => x.Key, x => x.Value.ToString()); + requestBody = System.Text.Json.JsonSerializer.Serialize(formData); + + } + catch (Exception) { } + } + var payload = _client.BuildPayload("DotNet", stopwatch, context.Request, statusCode, System.Text.Encoding.UTF8.GetBytes(requestBody), System.Text.Encoding.UTF8.GetBytes(responseBody), responseHeaders, pathParams, urlPath, errors, msg_id);