Add repeated parameter to Delphi’s Delphi component

Asked

Viewed 1,209 times

0

Good afternoon.

I am developing a class in Delphi, using the Boleto Cloud API. The class is now ready and functional, issuing billets and generating shipment.

This class consists of the REST Delphi components (Thttpbasicauthenticator, Trestresponse, Trestclient, Trestrequest), which will be generated dynamically at runtime.

The problem refers to the parameter boleto.instrucao, which in the API can be added repeatedly, thus generating the instruction lines.

But checking in my class, she adding only the last placed. Debugging the code, I realized that Delphi is omitting repeated parameters.

There is a PHP code of their API documentation, which they send this request in array format. However, I don’t know how to send in array, if the parameter that the Trequest component asks for is string.

Line that adds the parameter:

RSTRequest.AddParameter('....',FPagador.EnderecoComplemento,TRESTRequestParameterKind.pkGETorPOST);
.
.
.
. (mais de 10 parametros)

RSTRequest.AddParameter('boleto.instrucao',FInstrucao1.Text,TRESTRequestParameterKind.pkGETorPOST);
RSTRequest.AddParameter('boleto.instrucao',FInstrucao2.Text,TRESTRequestParameterKind.pkGETorPOST);
RSTRequest.AddParameter('boleto.instrucao',FInstrucao3.Text,TRESTRequestParameterKind.pkGETorPOST);

RSTRequest.Execute;

if RSTResponse.StatusCode <> 201 then
begin
    //erro
end
else
begin
    //sucesso
end;

1 answer

2


As the parameter accepts only string, just turn the JSON in string.

So to include a JSONArray do as follows:

var
    JSArray : TJSONArray;
begin
    JSArray  := TJSONArray.Create;
    try
        JSArray.Add('"Atenção! NÃO RECEBER ESTE BOLETO."');
        JSArray.Add('"Este é apenas um teste utilizando a API Boleto Cloud"');
        JSArray.Add('"Mais info em http://www.boletocloud.com/app/dev/api"');

        RESTRequest.AddParameter('boleto.instrucao',JSArray.ToString,TRESTRequestParameterKind.pkGETorPOST);
    finally
        JSArray.Free;
    end;

Not forgetting to declare in uses System.JSON and REST.Types

  • Thanks again Daniel for the help. Unfortunately it didn’t work. When sending, the boleto received the instruction without breaking the line and with errors in accented characters. In PHP works well. Still, thank you!

  • @André Try to put it like this: RESTRequest.AddParameter('boleto.instrucao',JSArray.ToString,TRESTRequestParameterKind.pkGETorPOST, [poDoNotEncode]);

Browser other questions tagged

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