lundi 1 février 2021

ERrorInWebProjectm In Web Api Project asp>net

Hi I have a web project --> Asp.Net Core Mvc I have a class called tokenmodel I get this error when requesting the API: UnsupportedMediaTypeException: No MediaTypeFormatter is available to read a "TokenModel" object of "text / plain" media content.

The description of my codes is as follows:

public class TokenModel
{
    public string Token { get; set; }
}

    
and In Auth Controller :
        var _Client = _httpClientFactory.CreateClient("MyApiClient");

        var jsonBody = JsonConvert.SerializeObject(login);

        StringContent content = new StringContent(jsonBody, Encoding.UTF8, "application/json");

        var response = _Client.PostAsync("/Api/Authentication", content).Result;

        if (response.IsSuccessStatusCode)
        {

            var token = response.Content.ReadAsAsync<TokenModel>().Result;
            
    



Aucun commentaire:

Enregistrer un commentaire