@@ -317,6 +317,30 @@ public static RestRequest AddBody(this RestRequest request, object obj, string?
317
317
throw new ArgumentException ( "Non-string body found with unsupported content type" , nameof ( obj ) ) ;
318
318
}
319
319
320
+ /// <summary>
321
+ /// Adds a string body and figures out the content type from the data format specified. You can, for example, add a JSON string
322
+ /// using this method as request body, using DataFormat.Json/>
323
+ /// </summary>
324
+ /// <param name="request">Request instance</param>
325
+ /// <param name="body">String body</param>
326
+ /// <param name="dataFormat"><see cref="DataFormat"/> for the content</param>
327
+ /// <returns></returns>
328
+ public static RestRequest AddStringBody ( this RestRequest request , string body , DataFormat dataFormat ) {
329
+ var contentType = ContentType . FromDataFormat [ dataFormat ] ;
330
+ request . RequestFormat = dataFormat ;
331
+ return request . AddParameter ( new BodyParameter ( "" , body , contentType ) ) ;
332
+ }
333
+
334
+ /// <summary>
335
+ /// Adds a string body to the request using the specified content type.
336
+ /// </summary>
337
+ /// <param name="request">Request instance</param>
338
+ /// <param name="body">String body</param>
339
+ /// <param name="contentType">Content type of the body</param>
340
+ /// <returns></returns>
341
+ public static RestRequest AddStringBody ( this RestRequest request , string body , string contentType )
342
+ => request . AddParameter ( new BodyParameter ( "" , body , Ensure . NotEmpty ( contentType , nameof ( contentType ) ) ) ) ;
343
+
320
344
/// <summary>
321
345
/// Adds a JSON body parameter to the request
322
346
/// </summary>
0 commit comments