Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix: default Content-Type to `x-www-form-urlencoded` when importing curl POST with body (#5040)

shuaixrdafe56cfe924
diff --git a/packages/hoppscotch-common/src/helpers/curl/curlparser.ts b/packages/hoppscotch-common/src/helpers/curl/curlparser.ts
index 9617d8fb9..0205ec8f2 100644
--- a/packages/hoppscotch-common/src/helpers/curl/curlparser.ts
+++ b/packages/hoppscotch-common/src/helpers/curl/curlparser.ts
@@ -132,7 +132,16 @@ export const parseCurlCommand = (curlCommand: string) => {
danglingParams = [...danglingParams, ...newQueries.danglingParams]
hasBodyBeenParsed = true
} else if (
- rawContentType.includes("application/x-www-form-urlencoded") &&
+ (rawContentType.includes("application/x-www-form-urlencoded") ||
+ /**
+ * When using the -d option with curl for a POST operation,
+ * curl includes a default header: Content-Type: application/x-www-form-urlencoded.
+ * https://everything.curl.dev/http/post/content-type.html
+ */
+ (!rawContentType &&
+ method === "POST" &&
+ rawData &&
+ rawData.length > 0)) &&
!!pairs &&
Array.isArray(rawData)
) {