Exception UnSupported media type using reset client in .NET 4.7.2 calling .NET 7 Ocelot gateway url

80 Views Asked by At

I have Abp project in .NET 7 and using Ocelot gateway when calling using REST client or http client. From .NET 6 it is working fine, but when calling from .NET framework, it throws an exception

Unsupported media type

My code is the same in the both cases:

var options = new RestClientOptions("my published gateway URL")
        {
            MaxTimeout = -1,
        };

var client = new RestClient(options);
var request = new RestRequest("my published gateway URL", Method.Post);

request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("AppCode", "CentralBank-IBANCheck");
request.AddHeader("AppSecretKey", "8e82265d-9d91-4e20-bd6b-2837886598b5");
request.AddHeader("RequestGUID", "e5bccab1-7dbb-4855-9d1e-db33433985bb");
// request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Accept-Encoding", "gzip, deflate, br");

var body = @"{" + "\n" +
         @"    ""nationalId"": ""1234566789""," + "\n" +
         @"    ""iban"": ""test""," + "\n" +
         @"    ""firstName"": ""name1""," + "\n" +
         @"    ""lastName"": ""name2""" + "\n" +
        @"}";
request.AddStringBody(body, DataFormat.Json);

var requestStr = JsonConvert.SerializeObject(request);
var httpContent = new StringContent(body, Encoding.UTF8, "application/json");

RestResponse response = client.ExecuteAsync(request).Result;
0

There are 0 best solutions below