Running a service: the following error happens. Newtonsoft.Json.Jsonreaderexception: Unexpected Character encountered while Parsing value

Asked

Viewed 829 times

2

Framework 4.0 Code block that generates the error

var token = Configuracao.Config.TokenAgrometrika;

if (Configuracao.Config.ValidateTokenAgrometrika > DateTime.Now) return token;

   var autenticacao = new Autenticacao()
   {
        Chave = Configuracao.Config.ChaveAgrometrika,
        ID = Configuracao.Config.IdAgrometrika
   };
Tools.Log(string.Format("Pegando token de autorização. Chave: {0} ID: {1}", autenticacao.Chave, autenticacao.ID));

var _cliente = new HttpClient(Handler, true);                   
var url = Configuracao.Config.Url.EndsWith("/") ? Configuracao.Config.Url : Configuracao.Config.Url + "/";

if (!Configuracao.Config.Url.EndsWith("api/") && !Configuracao.Config.Url.EndsWith("APIv2/"))
{
    url = Configuracao.Config.Url + "api/";                       
}                    
_cliente.BaseAddress = new Uri(url);
_cliente.DefaultRequestHeaders.Accept.Clear();
_cliente.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

*{Error happens here}*

var response = _cliente.PostAsJsonAsync("Autenticacao", autenticacao).Result;

Error after Response.

Error: Newtonsoft.Json.Jsonreaderexception: Unexpected Character encountered while Parsing value: <. Path '', line 0, position 0. em Newtonsoft.Json.JsonTextReader.ParseValue() em Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter) em Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) in Newtonsoft.Json.Jsonserializer.Deserializeinternal(Jsonreader Reader, Type objectType) in Newtonsoft.Json.Jsonconvert.Deserializeobject(String value, Type type, Jsonserializersettings Settings) in Newtonsoft.Json.Jsonconvert.Deserializeobject[T](String value, Jsonserializersettings Settings)

  • 1

    Check which is the return of the webservice, probably not a JSON.

  • We are in Stack Overflow in Portuguese and, as its name suggests, the language to be used should be Portuguese. Please re-edit your question and translate it. Before that, read as format your question correctly.

  • Problem it works when I am debugging, only error happens when Gero the exe and install the executable

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.