Jump to content

John Gambler

Members
  • Content Count

    2
  • Joined

  • Last visited

Everything posted by John Gambler

  1. John Gambler

    TRESTClient encode issue

    I have a small program(code bellow) to communicate with a rest API, everything works fine. My problem now is how can i fix the response values with diacritic character. Examples: correct string: não - received string: n\u00E3o correct string: padrão - received string: padr\u00E3o My code: unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Edit, FMX.Controls.Presentation, FMX.StdCtrls, REST.Types, Data.Bind.Components, Data.Bind.ObjectScope, REST.Client, FMX.Memo.Types, FMX.ScrollBox, FMX.Memo, System.JSON; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Send(Url : String); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.fmx} procedure TForm1.Send(Url : String); Var myClient : TRESTClient; myRequest : TRESTRequest; myResponse : TRESTResponse; Content : String; Begin myRequest := TRESTRequest.Create(Application); myResponse := TRESTResponse.Create(Application); myClient := TRESTClient.Create(nil); myRequest.Client := myClient; myRequest.Response := myResponse; Try myRequest.AddParameter('Content-Type', 'application/json', TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]); myRequest.AddParameter('Accept', 'application/json', TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]); myRequest.Method := TRESTRequestMethod.rmPOST; Content := '{"emptyString": "", "someUuid": "F60EB930-9B1B-11EF-9657-02240D86274B"}'; myRequest.Params.AddItem('body',Content,TRESTRequestParameterKind.pkREQUESTBODY,[],ctAPPLICATION_JSON); myRequest.Resource := Url; myRequest.Execute; Memo1.Lines.Add('objectProperty1: ' + (myResponse.JSONValue as TJSONObject).GetValue('objectProperty1').ToJSON()); Memo1.Lines.Add('objectProperty2: ' + (myResponse.JSONValue as TJSONObject).GetValue('objectProperty2').ToJSON()); Finally Resposta.Free; myRequest.Free; myClient.Free; End; End; procedure TForm1.Button1Click(Sender: TObject); begin Send('http://localhost:4000/local/'); end; procedure TForm1.Button2Click(Sender: TObject); begin Send('https://mystackurl.com'); end; End.
  2. John Gambler

    TRESTClient encode issue

    Thank you Remy and Uwe, both ways worked ok.
×