Error in Webservices Json C# "Unexpected Character encountered while Parsing value: <. Path '', line 0, position 0."

Asked

Viewed 6,168 times

1

Hello, I’m getting an error in the execution of my code, in another application the same code works, I’ve changed the using, but it doesn’t work.

public String CriaPeca(String token, String ip, String autor, bool seguranca, Dictionary<String, String> metadadosDoc, String nomeArquivo)
{
    // Variáveis para retorno do webservice e do método
    //var WSResult = "";
    var id = "";

    // Configuração dos parametros de entrada
    var URL_Base = "";

    // Caso exista necessidade de segurança deve ser usado HTTPS
    if (seguranca)
        URL_Base = "https://";
    else URL_Base = "http://";

    URL_Base = URL_Base + ip + "/docflow/";

    var URL_Servico = "ws/peca/cadastro?auth=" + token;

    // Criando metadados gerais para o documento
    var metadados = "login_autor=" + autor;

    // Montando metadados especificos do documento
    var metTemp = metadadosDoc;
    // Concatenando metadados gerais com especificos
    metadados = metadados + "&" + metTemp;

    try
    {
        var client = new RestClient(URL_Base);
        // Neste ploco fazemos o cadastro da Peça
        var request = new RestRequest(URL_Servico, Method.POST);


        request.AddQueryParameter("response_type", "json");
        request.AddParameter("user_login", "admin");
        request.AddFile("bin_peca", nomeArquivo);
        request.AddHeader("Content-type", "application/json");

        foreach (String campo in metadadosDoc.Keys)
        {
            String metadadoslimpo = removerAcentos(metadadosDoc[campo]);
            request.AddParameter(campo, metadadoslimpo);
        }

        var response = client.Execute(request);


        Console.Out.WriteLine(response.Content);


            //Erro // Erro // Erro
        JObject ResultJObject = JObject.Parse(response.Content);

        var status = ResultJObject["message"]["type"].Value<string>();
        if (status.Equals("error"))
        {
            status = ResultJObject["message"]["value"].Value<string>();
        }
        id = status;

    }
    catch (Exception ex)
    {
        id = Convert.ToString(ex);
        Console.WriteLine("--> Nao foi possivel criar o documento via WebService <--\nErro: " + ex.ToString());
    }

    return id;
}

The error message is this.

Unexpected Character encountered while Parsing value: <. Path '', line 0, position 0.

Sponse. Content is thus

inserir a descrição da imagem aqui

  • 1

    Please avoid using images when message can be displayed via text.

1 answer

2


Webservice returned an HTML page specifying an error. Notice the tag title in Response.Content

Jboss Web/7.0.10.Final - Error Report

The code tries to treat the return as a JSON, but it is an HTML, this is the cause of the error.

  • Strange because I send the Addqueryparameter to receive json, the webservices gives me the return of the two ways, I’m sending wrong ?

  • @Renansilveira Not necessarily. Apparently the server is not "giving ball" to what you want to receive. Remember that the server response may be completely different from what you expect, it has no "obligation" to send the data as you expect. See what error message he’s sending you, it should give you a north.

  • I get it, thank you

Browser other questions tagged

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