Extension for send a jSon to a webService

Hi everyone,

I'm creating a extension for a cloud installation to send a jSon to a external webService. The code is like this:

 procedure SendContacts(var pContactTxt: text)
    var
        lMensaje: Text;
    begin
        Content.Clear();
        Content.GetHeaders(Headers);
        lMensaje := pContactTxt;
        Content.WriteFrom(lMensaje);
        Headers.Remove('Content-Type');
        Headers.Remove('Charset');
        Headers.Add('Content-Type', 'application/json');
        Headers.Add('Charset', 'utf-8');
        httpRequest.Content(Content);
        httpRequest.Method('POST');

        url := 'http://xxxxxx.com/webservice/create-contact';
        client.Clear();
        Client.SetBaseAddress(url);

        if not Client.Send(httpRequest, ResponseMessage) then
            error('Llamada incorrecta');
        if not ResponseMessage.IsSuccessStatusCode then
            Error('El WS ha devuelto el siguiente error:\' +
            'Status Code : %1\' +
            'Descripcion: %2',
            ResponseMessage.HttpStatusCode,
            ResponseMessage.ReasonPhrase);

        ResponseMessage.Content.ReadAs(ResponseText);
        Message('Contacto(s) enviados a Gremious');
    end;

If I use "RequestBin" for testing, you can see that the message seems to be correct:

And if I copy the request content, adn send it to the real WebServiche through Postman, we can see in the WebService's log that the message arrives correctly:

But if I send directly to the webService from BC, I get this error:

And this can be seen into the webService log:

Seems that the jSOn is sent as an array, and the webService isn't capable to process it. Am I sending he content incorrectly?

Thank you all

Parents Reply Children
Related
Recommended