From be18b103b76b71503d49aaddb1c8f3a08a11e695 Mon Sep 17 00:00:00 2001 From: Jiakaic <66515011+Jiakaic@users.noreply.github.com> Date: Fri, 28 Feb 2025 14:58:01 +0800 Subject: [PATCH] fix: set method to POST when body exists (#14523) (#14524) --- .../workflow/nodes/http/components/curl-panel.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web/app/components/workflow/nodes/http/components/curl-panel.tsx b/web/app/components/workflow/nodes/http/components/curl-panel.tsx index 9c5dddedb73971..cd0549bb2e9664 100644 --- a/web/app/components/workflow/nodes/http/components/curl-panel.tsx +++ b/web/app/components/workflow/nodes/http/components/curl-panel.tsx @@ -22,13 +22,14 @@ const parseCurl = (curlCommand: string): { node: HttpNodeType | null; error: str const node: Partial = { title: 'HTTP Request', desc: 'Imported from cURL', - method: Method.get, + method: undefined, url: '', headers: '', params: '', body: { type: BodyType.none, data: '' }, } const args = curlCommand.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g) || [] + let hasData = false for (let i = 1; i < args.length; i++) { const arg = args[i].replace(/^['"]|['"]$/g, '') @@ -38,6 +39,7 @@ const parseCurl = (curlCommand: string): { node: HttpNodeType | null; error: str if (i + 1 >= args.length) return { node: null, error: 'Missing HTTP method after -X or --request.' } node.method = (args[++i].replace(/^['"]|['"]$/g, '') as Method) || Method.get + hasData = true break case '-H': case '--header': @@ -89,6 +91,9 @@ const parseCurl = (curlCommand: string): { node: HttpNodeType | null; error: str } } + // Determine final method + node.method = node.method || (hasData ? Method.post : Method.get) + if (!node.url) return { node: null, error: 'Missing URL or url not start with http.' }