diff --git a/src/main/resources/template/js/debug.js b/src/main/resources/template/js/debug.js index 2541df7..26264ac 100644 --- a/src/main/resources/template/js/debug.js +++ b/src/main/resources/template/js/debug.js @@ -277,10 +277,12 @@ function toCurl(request) { if (request.url.indexOf('https') == 0) { cmd.push("-k"); } + // append Content-Type - if (request.data && request.data.length > 0) { + if (request.contentType) { cmd.push("-H"); - cmd.push("'Content-Type: application/json; charset=utf-8'"); + cmd.push("'Content-Type:"); + cmd.push(request.contentType+"'"); } // append request headers let headerValue; @@ -310,10 +312,39 @@ function toCurl(request) { } cmd.push(url); // append data - if (request.data && request.data.length > 0) { + + if (typeof request.data == 'object') { + let index = 0; + const bodyData = []; + bodyData.push("\"") + for (let key in request.data) { + if (Object.prototype.hasOwnProperty.call(request.data, key)) { + if (index===0){ + bodyData.push(key); + bodyData.push("="); + bodyData.push(request.data[key]); + } else { + bodyData.push("&") + bodyData.push(key); + bodyData.push("="); + bodyData.push(request.data[key]); + } + } + index++; + } + bodyData.push("\""); + let bodyStr = "" + bodyData.forEach(function (item) { + bodyStr += item; + }); + cmd.push("--data"); + cmd.push(bodyStr); + } else if (request.data && request.data.length > 0) { + // append json data cmd.push("--data"); cmd.push("'" + request.data + "'"); } + let curlCmd = ""; cmd.forEach(function (item) { curlCmd += item + " ";