You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is possible to override the default content type by supplying the `contentType` argument. For example:
350
+
351
+
```csharp
352
+
request.AddJsonBody(param, "text/x-json");
353
+
```
354
+
355
+
If you use a pre-serialized string with `AddJsonBody`, it will be sent as-is. The `AddJsonBody` will detect if the parameter is a string and will add it as a string body with JSON content type.
356
+
Essentially, it means that top-level strings won't be serialized as JSON when you use `AddJsonBody`. To overcome this issue, you can use an overload of `AddJsonBody`, which allows you to tell RestSharp to serialize the string as JSON:
357
+
358
+
```csharp
359
+
conststringpayload=@"
360
+
""requestBody"": {
361
+
""content"": {
362
+
""application/json"": {
363
+
""schema"": {
364
+
""type"": ""string""
365
+
}
366
+
}
367
+
}
368
+
},";
369
+
request.AddJsonBody(payload, forceSerialize: true); // the string will be serialized
370
+
request.AddJsonBody(payload); // the string will NOT be serialized and will be sent as-is
371
+
```
372
+
353
373
#### AddXmlBody
354
374
355
375
When you call `AddXmlBody`, it does the following for you:
0 commit comments