@@ -22,6 +22,7 @@ limitations under the License.
2222using System ;
2323using System . Net . Http ;
2424using System . Text ;
25+ using System . Text . Json ;
2526using System . Threading . Tasks ;
2627
2728namespace Amdocs . Ginger . CoreNET . External . WireMock
@@ -99,7 +100,8 @@ public async Task<string> StartRecordingAsync(string targetUrl)
99100
100101 using ( HttpClient client = new HttpClient ( ) )
101102 {
102- var content = new StringContent ( $ "{{\" targetBaseUrl\" : \" { targetUrl } \" }}", Encoding . UTF8 , "application/json" ) ;
103+ string json = JsonSerializer . Serialize ( new { targetBaseUrl = targetUrl } ) ;
104+ var content = new StringContent ( json , Encoding . UTF8 , "application/json" ) ;
103105 HttpResponseMessage response = await client . PostAsync ( $ "{ NormalizeUrl ( GingerCore . ValueExpression . PasswordCalculation ( _baseUrl ) ) } { StartRecordingEndpoint } ", content ) ;
104106 response . EnsureSuccessStatusCode ( ) ;
105107 return await response . Content . ReadAsStringAsync ( ) ;
@@ -153,7 +155,19 @@ public async Task<string> CreateStubAsync(string stubMapping, string contentType
153155 {
154156 contentType = "application/json" ;
155157 }
156- var content = new StringContent ( stubMapping , Encoding . UTF8 , contentType ) ;
158+
159+ string body ;
160+ if ( string . IsNullOrEmpty ( stubMapping ) )
161+ {
162+ body = stubMapping ;
163+ }
164+ else
165+ {
166+ using JsonDocument doc = JsonDocument . Parse ( stubMapping ) ;
167+ body = doc . RootElement . GetRawText ( ) ;
168+ }
169+
170+ var content = new StringContent ( body , Encoding . UTF8 , contentType ) ;
157171 HttpResponseMessage response = await client . PostAsync ( $ "{ NormalizeUrl ( GingerCore . ValueExpression . PasswordCalculation ( _baseUrl ) ) } { MappingEndpoint } ", content ) ;
158172 response . EnsureSuccessStatusCode ( ) ;
159173 return await response . Content . ReadAsStringAsync ( ) ;
@@ -204,7 +218,18 @@ public async Task<string> UpdateStubAsync(string stubId, string stubMapping)
204218
205219 using ( HttpClient client = new HttpClient ( ) )
206220 {
207- var content = new StringContent ( stubMapping , Encoding . UTF8 , "application/json" ) ;
221+ string body ;
222+ if ( string . IsNullOrEmpty ( stubMapping ) )
223+ {
224+ body = stubMapping ;
225+ }
226+ else
227+ {
228+ using JsonDocument doc = JsonDocument . Parse ( stubMapping ) ;
229+ body = doc . RootElement . GetRawText ( ) ;
230+ }
231+
232+ var content = new StringContent ( body , Encoding . UTF8 , "application/json" ) ;
208233 HttpResponseMessage response = await client . PutAsync ( $ "{ NormalizeUrl ( GingerCore . ValueExpression . PasswordCalculation ( _baseUrl ) ) } { MappingEndpoint } /{ stubId } ", content ) ;
209234 response . EnsureSuccessStatusCode ( ) ;
210235 return await response . Content . ReadAsStringAsync ( ) ;
0 commit comments