Jump to content
ottojr

[Delphi 10.3] How to use TSslHttpRest one more time?

Recommended Posts

Good morning guys. I hope you are well!
In the example below I have 2 procedures. In the procedure test_1 the StatCode is 200, so far everything is ok!, but in the procedure test_2 the
StatCode is 400 (Bad resquest).

Do I have to do any more programming to close the api calls?

 

procedure tform1.teste_1;
begin
   try
     With SslHttpRest1 Do
     begin
       ContentTypePost := 'application/json';

       RestParams.Clear();
       ExtraHeaders.Add( 'Store-Token: '+ WS_token_f);
       ExtraHeaders.Add( 'Authorization: token='+ WS_token_m);
       ExtraHeaders.Add( 'Authentication-Token: '+ WS_token_f );

       RestParams.PContent := PContBodyJson;
       StatCode := RestRequest(httpPOST, AddressWS, False, JSONObj.ToString);

       lsMsg := sLineBreak +
                'Headers: ' + sLineBreak +
                RcvdHeader.Text + sLineBreak +
                'Status code: ' + IntToStr(StatusCode) + sLineBreak +
                'nStatusCode: ' + IntToStr(nStatCode);
       memolog.Lines.Add(lsMsg);
     end;
   finally
     SslHttpRest1.Close;
   end;
end;

 

procedure tform1.teste_2;
begin
   try
     With SslHttpRest1 Do
     begin
       ContentTypePost := 'application/json';

       RestParams.Clear();
       ExtraHeaders.Add( 'Store-Token: '+ WS_token_f);
       ExtraHeaders.Add( 'Authorization: token='+ WS_token_m);
       ExtraHeaders.Add( 'Authentication-Token: '+ WS_token_f );

       RestParams.PContent := PContBodyJson;
       StatCode := RestRequest(httpPOST, AddressWS, False, JSONObj.ToString);

       lsMsg := sLineBreak +
                'Headers: ' + sLineBreak +
                RcvdHeader.Text + sLineBreak +
                'Status code: ' + IntToStr(StatusCode) + sLineBreak +
                'nStatusCode: ' + IntToStr(nStatCode);
       memolog.Lines.Add(lsMsg);
     end;
   finally
     SslHttpRest1.Close;
   end;
end;

 

 

 

Share this post


Link to post

To my eye, the two procedures seem to be identical, so I can only assume the different result is due to different parameters to the two procedures.  

 

BTW, since you are using the RawParams option in RestRequest, RestParams are ignored. 

 

Angus

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×