From 7f1ecd3e5cf555f0e801277055a7c358e93ca2db Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 21 Nov 2024 14:56:09 +0100 Subject: [PATCH] fix gloo post params --- src/frontend/api.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/frontend/api.rs b/src/frontend/api.rs index dcf50c7..5687331 100644 --- a/src/frontend/api.rs +++ b/src/frontend/api.rs @@ -286,11 +286,11 @@ impl ApiClient { }); let path_with_endpoint = self.request_endpoint(path); + let params_encoded = serde_urlencoded::to_string(¶ms).unwrap(); let path = if method == Method::GET { // Cannot pass the struct directly but need to convert it manually // https://github.com/rustwasm/gloo/issues/378 - let query = serde_urlencoded::to_string(¶ms).unwrap(); - format!("{path_with_endpoint}?{query}") + format!("{path_with_endpoint}?{params_encoded}") } else { path_with_endpoint }; @@ -299,7 +299,9 @@ impl ApiClient { .abort_signal(abort_signal.as_ref()) .credentials(RequestCredentials::Include); let req = if method == Method::POST { - builder.json(¶ms) + builder + .header("content-type", "application/x-www-form-urlencoded") + .body(params_encoded) } else { builder.build() }