I got this error
{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:{ Transfer-Encoding: chunked Server: Microsoft-IIS/10.0 X-Powered-By: ASP.NET Date: Tue, 02 May 2023 10:38:30 GMT Content-Type: application/problem+json; charset=utf-8}}
After I updated the .net from 3.1 to 7.0.
Here is the rest client code:
var obj = new Login();
using var httpClient = new HttpClient();
HttpClientHelper.SetupClient(httpClient);
StringContent content = new StringContent(JsonConvert.SerializeObject(loginObj), Encoding.UTF8, "application/json");
using var response = await httpClient.PostAsync(apiName + "/UserLogin", content);
string apiResponse = await response.Content.ReadAsStringAsync();
obj = JsonConvert.DeserializeObject<Login>(apiResponse);
httpClient.Dispose();
response.Dispose();
return obj;
The same code was running fine.
UPDATE I discovered that objects containing some null values are not accepted after updating .NET version.