@@ -41,6 +41,21 @@ function parseContentType (request) {
41
41
return request . getHeaders ( { enabled : true , ignoreCase : true } ) [ 'content-type' ] || 'text/plain' ;
42
42
}
43
43
44
+ /**
45
+ * Generates a parameter using AddStringBody method
46
+ *
47
+ * @param {Object } requestBody - JSON object representing body of request
48
+ * @param {string } dataFormat - the data format to use "DataFormat.Json" or "DataFormat.Xml"
49
+ * @returns {String } snippet of the parameter generation
50
+ */
51
+ function getAddStringBodyParam ( requestBody , dataFormat ) {
52
+ return `var body = ${ requestBody [ requestBody . mode ]
53
+ . split ( '\n' )
54
+ . map ( ( line ) => { return '@"' + line . replace ( / " / g, '""' ) + '"' ; } )
55
+ . join ( ' + "\\n" +\n' ) } ;\n` +
56
+ `request.AddStringBody(body, ${ dataFormat } );\n` ;
57
+ }
58
+
44
59
/**
45
60
* Parses Raw data
46
61
*
@@ -52,11 +67,10 @@ function parseRawBody (request, requestBody) {
52
67
let bodySnippet = '' ,
53
68
contentType = parseContentType ( request ) ;
54
69
if ( contentType && ( contentType === 'application/json' || contentType . match ( / \+ j s o n $ / ) ) ) {
55
- bodySnippet = `var body = ${ requestBody [ requestBody . mode ]
56
- . split ( '\n' )
57
- . map ( ( line ) => { return '@"' + line . replace ( / " / g, '""' ) + '"' ; } )
58
- . join ( ' + "\\n" +\n' ) } ;\n` +
59
- 'request.AddStringBody(body, DataFormat.Json);\n' ;
70
+ bodySnippet = getAddStringBodyParam ( requestBody , 'DataFormat.Json' ) ;
71
+ }
72
+ else if ( contentType && ( contentType === 'text/xml' || contentType . match ( / \+ x m l $ / ) ) ) {
73
+ bodySnippet = getAddStringBodyParam ( requestBody , 'DataFormat.Xml' ) ;
60
74
}
61
75
else {
62
76
bodySnippet = `var body = ${ requestBody [ requestBody . mode ]
0 commit comments