@@ -37,7 +37,15 @@ module.exports = function (source, options) {
3737
3838 switch ( source . postData . mimeType ) {
3939 case 'application/x-www-form-urlencoded' :
40- reqOpts . body = source . postData . paramsObj
40+ code . unshift ( 'const { URLSearchParams } = require(\'url\');' )
41+ code . push ( 'const encodedParams = new URLSearchParams();' )
42+ code . blank ( )
43+
44+ source . postData . params . forEach ( function ( param ) {
45+ code . push ( 'encodedParams.set(\'' + param . name + '\', \'' + param . value + '\');' )
46+ } )
47+
48+ reqOpts . body = 'encodedParams'
4149 break
4250
4351 case 'application/json' :
@@ -49,15 +57,16 @@ module.exports = function (source, options) {
4957 case 'multipart/form-data' :
5058 code . unshift ( 'const FormData = require(\'form-data\');' )
5159 code . push ( 'const formData = new FormData();' )
60+ code . blank ( )
61+
5262 source . postData . params . forEach ( function ( param ) {
5363 if ( ! param . fileName && ! param . fileName && ! param . contentType ) {
54- code . push ( 'formData.append(\'' + param . name + '\',\'' + param . value + '\');' )
64+ code . push ( 'formData.append(\'' + param . name + '\', \'' + param . value + '\');' )
5565 return
5666 }
5767
5868 if ( param . fileName ) {
5969 includeFS = true
60- code . blank ( )
6170 code . push ( 'formData.append(\'' + param . name + '\', fs.createReadStream(\'' + param . fileName + '\'));' )
6271 }
6372 } )
@@ -100,7 +109,9 @@ module.exports = function (source, options) {
100109 . push ( 1 , '.then(json => console.log(json))' )
101110 . push ( 1 , '.catch(err => console.error(\'error:\' + err));' )
102111
103- return code . join ( ) . replace ( / " f s \. c r e a t e R e a d S t r e a m \( \\ " ( .+ ) \\ " \) " / , 'fs.createReadStream("$1")' )
112+ return code . join ( )
113+ . replace ( / ' e n c o d e d P a r a m s ' / , 'encodedParams' )
114+ . replace ( / " f s \. c r e a t e R e a d S t r e a m \( \\ " ( .+ ) \\ " \) " / , 'fs.createReadStream("$1")' )
104115}
105116
106117module . exports . info = {
0 commit comments