Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TThreadBoleto.Execute;
- var
- RCtx : TRttiContext;
- RType : TRttiType;
- RProp : TRttiProperty;
- I : integer;
- PDF : TFile;
- begin
- try
- try
- RClient := TRESTClient.Create('');
- with RClient do begin
- AcceptEncoding := 'identity';
- FallbackCharsetEncoding := 'UTF-8';
- Accept := 'application/json;text/plain;application/pdf;';
- AcceptCharset := 'UTF-8';
- BaseURL := 'https://sandbox.boletocloud.com/api/v1/boletos';
- ContentType := 'application/x-www-form-urlencoded';
- HandleRedirects := true;
- RCtx := TRttiContext.Create;
- RType := RCtx.GetType(THRBoleto.ClassType);
- I := 0;
- for RProp in RType.GetProperties do
- begin
- Params.AddItem;
- Params.Items[I].name := LowerCase(RProp.Name.Replace('_','.'));
- Params.Items[I].Value := RProp.GetValue(THRBoleto).AsString;
- I := I + 1;
- end;
- end;
- RRequest := TRESTRequest.Create(RRequest);
- with RRequest do begin
- Accept := 'application/json;text/plain;application/pdf;';
- Client := RClient;
- Method := rmPost;
- SynchronizedEvents := false;
- AcceptCharset := 'UTF-8';
- end;
- RResponse := TRESTResponse.Create(RResponse);
- RResponse.ContentType := 'application/pdf;*/*;';
- RResponse.ContentEncoding := 'UTF-8';
- RAuth := THTTPBasicAuthenticator.Create('','');
- with RAuth do begin
- Username := 'anAPItokenAccess';
- Password := 'token';
- end;
- RClient.Authenticator := RAuth;
- RRequest.Response := RResponse;
- RRequest.Execute;
- PDF.WriteAllBytes(ExtractFilePath(Application.ExeName)+'boleto.pdf',RResponse.RawBytes);
- OutputStrings.Add(RResponse.Content);
- OutputStrings.Add('');
- OutputStrings.Add('');
- OutputStrings.AddStrings(RResponse.Headers);
- except on E:Exception do
- ShowMessage('Error: '+E.Message);
- end;
- finally
- THRBoleto.Free;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement