Unknown error in integration with Webservice REST

Asked

Viewed 595 times

1

I am trying to make a POST type request using the components: Resrrequest, Restclient, Restresponse by Delphi Xe8.

In the GET type integration I can do normally, I get the return normally from the server.

However, when doing the integration via POST is giving an exception in the execution: "Execution of request terminated with Unknown error".

Maybe I’m missing something. The server expects 2 parameters:

1 - HeaderParam, tipo AlfaNumérico, Identificador "Token-Integracao"
2 - BodyParam, tipo Complexo, Identificador "itensResolvidos"

Follow the code I’m using to do the integration:

with fDm do
begin
  sRet := EmptyStr;

  RESTClient.BaseURL := sInfo[7];
  RESTClient.Params.ParameterByName('Token-Integracao').Value := sInfo[6];

  with RESTClient.Params.AddItem do
  begin
    name := 'itensResolvidos';
    Value := sJson; // String com o JSON a ser enviado, montado anteriormente
    Kind := TRESTRequestParameterKind.pkREQUESTBODY;
  end;

  RESTRequest.Method := rmPOST;
  RESTRequest.Execute; // Aqui dá a Excessão e não continua o programa

  sRet := '{"retorno":' + RESTResponse.JSONValue.ToString + '}';
end;
  • For the token you have to create a header type parameter, do the same as you did to create the parameter for solved items only in type choose pkHTTPHEADER. Because the return waits for the token via header.

  • The token I created directly in the component, because I’m using the Restclient component to make the GET, and it worked. Still I will do what you said, create the same way as the other to see if this is it. Thank you!

  • Anything, try to take the test for Postman

  • 1

    I put the Token the same way, did not solve. I’m going to test by Postman. Thanks!

1 answer

1


Use as follows::

RESTClient.BaseURL := MINHA_URL;
Requisicao.Method := TRESTRequestMethod.rmPOST;
Requisicao.Resource := '/REQUISICAO_QUALQUER';
Requisicao.Params.AddItem('username', aUsuario, TRESTRequestParameterKind.pkGETorPOST);
Requisicao.Params.AddItem('password', aSenha, TRESTRequestParameterKind.pkGETorPOST);
Requisicao.Execute;

TRESTRequestMethod.rmPOST; this should solve your problem.

So much for GET how much to POST should be specified for each parameter what it is doing. In this case, I use the pkGETorPOST.

As for the Token the submission is as follows:

Requisicao.Params.AddItem('Authorization'
                          ,SEU_TOKEN
                          ,TRESTRequestParameterKind.pkHTTPHEADER
                          ,[poDoNotEncode]
                          ,ctAPPLICATION_JSON);

As for the JSON sending is as follows:

Requisicao.AddBody(SEU_JSON, TRESTContentType.ctAPPLICATION_JSON);
  • Junior, I adapted some things that were missing, but it still hasn’t solved. The unknown error still appears. By POSTMAN I got it, but I still don’t know what I need to do in Delphi to make it work properly. I will continue doing tests and return here to say the result. Thank you so much so far

  • Junior, I made it! I was making a rookie mistake here! sometimes I’m ashamed I didn’t pay attention to something simple that I was wrong... Your way worked out. Thank you very much!

Browser other questions tagged

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