diff --git a/src/NSwag.CodeGeneration.CSharp.Tests/ObjectParameterTests.cs b/src/NSwag.CodeGeneration.CSharp.Tests/ObjectParameterTests.cs index 30ff32567c..efdb7fc630 100644 --- a/src/NSwag.CodeGeneration.CSharp.Tests/ObjectParameterTests.cs +++ b/src/NSwag.CodeGeneration.CSharp.Tests/ObjectParameterTests.cs @@ -73,7 +73,7 @@ public async Task when_content_is_formdata_with_property_object_then_content_sho // Assert Assert.Contains("var content_ = new System.Net.Http.MultipartFormDataContent(boundary_);", code); Assert.Contains("var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(propertyDto, _settings.Value)", code); - Assert.Contains("content_.Add(new System.Net.Http.StringContent(json_), \"propertyDto\");", code); + Assert.Contains("content_.Add(new System.Net.Http.StringContent(json_, System.Text.Encoding.UTF8, \"application/json\"), \"propertyDto\");", code); } } } diff --git a/src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid b/src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid index 982c8a0d97..a8bc24be9a 100644 --- a/src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid +++ b/src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid @@ -270,7 +270,7 @@ } {% elsif parameter.IsObject -%} var json_ = {% if UseSystemTextJson %}System.Text.Json.JsonSerializer.Serialize{% else %}Newtonsoft.Json.JsonConvert.SerializeObject{% endif %}({{ parameter.VariableName }}, {% if UseRequestAndResponseSerializationSettings %}_requestSettings{% else %}_settings{% endif %}.Value); - content_.Add(new System.Net.Http.StringContent(json_), "{{ parameter.Name }}"); + content_.Add(new System.Net.Http.StringContent(json_, System.Text.Encoding.UTF8, "application/json"), "{{ parameter.Name }}"); {% else -%} content_.Add(new System.Net.Http.StringContent(ConvertToString({{ parameter.VariableName }}, System.Globalization.CultureInfo.InvariantCulture)), "{{ parameter.Name }}"); {% endif -%}