FNCRESTClient full request

Hi,
We are tracing an access problem to an api rest of the french government with the INSEE agency and they are asking me the full request sent by the restclient component (method + URL + Headers + authorization token + postdata) not only the url. Is it accessible before or after the executerequest ?

Thanks for your help.

Regards
Greg

Hello,

You can get the full request just before it is sent. Use the OnExecuteRequest event of TTMSFNCRESTClient.

When you call ExecuteRequest (or any of the ExecuteRequestWith… variants), the component copies your Request settings into a low-level TTMSFNCCloudBaseRequest. That includes the authorization, which is added as a header, or as a query parameter when you use atKeyQuery. Then it fires OnExecuteRequest with that object and sends the HTTP call. So in this event you see exactly what will go on the wire:

procedure TForm1.TMSFNCRESTClient1ExecuteRequest(Sender: TObject;
  ACloudBaseRequest: TTMSFNCCloudBaseRequest);
var
  I: Integer;
  sl: TStringList;
begin
  sl := TStringList.Create;
  try
    sl.Add('Method: ' + ACloudBaseRequest.GetMethodString);
    sl.Add('URL: ' + ACloudBaseRequest.GetURL);
    sl.Add('Headers:');
    for I := 0 to ACloudBaseRequest.Headers.Count - 1 do
      sl.Add('  ' + ACloudBaseRequest.Headers[I].Name + ': ' + ACloudBaseRequest.Headers[I].Value);
    sl.Add('Body:');
    sl.Add(ACloudBaseRequest.PostData);
    sl.SaveToFile('request_trace.txt');
  finally
    sl.Free;
  end;
end;

Notes:

  • The Authorization header shows up in the Headers list. With AuthorizationType = atBearerToken, check that AuthorizationValue holds Bearer <token>, with the Bearer prefix followed by the token. With atBasic, the value is computed as Basic base64(username:password).
  • After execution, ExecutedRequests (and the ARequest parameter in OnRequestResponseRetrieved) holds a copy of your request settings plus the response: status code, response headers and body. The INSEE support team may also want the response headers.
  • The operating system’s HTTP stack can add a few standard headers on its own, such as Host, User-Agent, Content-Length and Accept-Encoding. These are not in the list above. If INSEE needs the exact raw bytes, a proxy such as Fiddler will show them. Please remove the token before you send a trace to a third party.

Best regards,