From c8d176485f7d44f3960d081036843463bd2f1969 Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Mon, 12 Dec 2016 14:37:20 +0100 Subject: [PATCH] Fix with german chars --- .../BasicDemoVCLClient.dproj | 432 +++++++++++++++++- samples/basicdemo_vclclient/Unit1.dfm | 9 + samples/basicdemo_vclclient/Unit1.pas | 21 +- sources/MVCFramework.RESTClient.pas | 77 ++-- unittests/TestServer/TestServer.dproj | 22 +- 5 files changed, 505 insertions(+), 56 deletions(-) diff --git a/samples/basicdemo_vclclient/BasicDemoVCLClient.dproj b/samples/basicdemo_vclclient/BasicDemoVCLClient.dproj index 4772cc8b..86c61d6a 100644 --- a/samples/basicdemo_vclclient/BasicDemoVCLClient.dproj +++ b/samples/basicdemo_vclclient/BasicDemoVCLClient.dproj @@ -1,7 +1,7 @@  {9C7C2C86-CD2A-4B2A-8588-80CF23B7CF0F} - 14.4 + 18.2 VCL BasicDemoVCLClient.dpr True @@ -40,6 +40,7 @@ true + BasicDemoVCLClient System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) None 1031 @@ -55,14 +56,18 @@ false + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png + true true IndyIPClient;JvGlobus;JvMM;JvManagedThreads;DBXSqliteDriver;fmx;JvDlgs;IndySystem;JvCrypt;TeeDB;vclib;inetdbbde;DBXInterBaseDriver;DataSnapClient;DataSnapCommon;DataSnapServer;JvNet;DataSnapProviderClient;JvDotNetCtrls;DBXSybaseASEDriver;TMSMenusDXE3;DbxCommonDriver;ATBWizardPkgDXE3;vclimg;FIBPlus_XE3;dbxcds;dclCrossTalk_XE3;DatasnapConnectorsFreePascal;MetropolisUILiveTile;JvXPCtrls;vcldb;vcldsnap;DBXDb2Driver;DBXOracleDriver;CustomIPTransport;JvCore;vclribbon;dsnap;IndyIPServer;FixInsight_XE3;fmxase;vcl;IndyCore;IndyIPCommon;CloudService;DBXMSSQLDriver;FmxTeeUI;JvAppFrm;JvDB;JvRuntimeDesign;inetdbxpress;webdsnap;JclDeveloperTools;JvDocking;adortl;JvWizards;JvHMI;bindcompfmx;JvBands;vcldbx;Intraweb_14_DXE3;rtl;dbrtl;DbxClientDriver;bindcomp;inetdb;JvPluginSystem;Tee;JclContainers;DBXOdbcDriver;JvCmp;JvSystem;xmlrtl;svnui;ibxpress;JvTimeFramework;JvControls;IndyProtocols;DBXMySQLDriver;vclactnband;bindengine;soaprtl;bindcompdbx;FMXTee;TeeUI;bindcompvcl;JvStdCtrls;JvCustom;Jcl;vclie;JvJans;JvPageComps;JvPrintPreview;vcltouch;websnap;VclSmp;DBXInformixDriver;DataSnapConnectors;DelphiModbusXE3;dsnapcon;DBXFirebirdDriver;inet;fmxobj;JclVcl;JvPascalInterpreter;vclx;svn;DBXSybaseASADriver;fmxdae;bdertl;VirtualTreesR;dbexpress;DataSnapIndy10ServerTransport;JvBDE;$(DCC_UsePackage) 1033 - CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= $(BDS)\bin\default_app.manifest Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png IndyIPClient;DBXSqliteDriver;fmx;IndySystem;DBXInterBaseDriver;DataSnapClient;DataSnapCommon;DataSnapServer;DataSnapProviderClient;DBXSybaseASEDriver;DbxCommonDriver;vclimg;FIBPlus_XE3;dbxcds;vcldb;vcldsnap;DBXDb2Driver;DBXOracleDriver;CustomIPTransport;dsnap;IndyIPServer;fmxase;vcl;IndyCore;IndyIPCommon;DBXMSSQLDriver;inetdbxpress;webdsnap;adortl;bindcompfmx;rtl;dbrtl;DbxClientDriver;bindcomp;inetdb;DBXOdbcDriver;xmlrtl;IndyProtocols;DBXMySQLDriver;vclactnband;bindengine;soaprtl;bindcompdbx;bindcompvcl;vclie;vcltouch;websnap;VclSmp;DBXInformixDriver;dsnapcon;DBXFirebirdDriver;inet;fmxobj;vclx;DBXSybaseASADriver;fmxdae;dbexpress;DataSnapIndy10ServerTransport;$(DCC_UsePackage) @@ -74,6 +79,8 @@ true + Debug + true $(BDS)\bin\default_app.manifest 1033 true @@ -83,7 +90,7 @@ false RELEASE;$(DCC_Define) 0 - false + 0 @@ -153,7 +160,423 @@ Microsoft Office XP Beispiele für gekapselte Komponenten für Automation Server - + + + + 0 + .dll;.bpl + + + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + + + Contents\Resources + 1 + + + + + classes + 1 + + + + + Contents\MacOS + 0 + + + 1 + + + Contents\MacOS + 1 + + + + + 1 + + + 1 + + + 1 + + + + + res\drawable-xxhdpi + 1 + + + + + library\lib\mips + 1 + + + + + 1 + + + 1 + + + 0 + + + 1 + + + Contents\MacOS + 1 + + + library\lib\armeabi-v7a + 1 + + + 1 + + + + + 0 + + + Contents\MacOS + 1 + .framework + + + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + library\lib\armeabi + 1 + + + + + 0 + + + 1 + + + Contents\MacOS + 1 + + + + + 1 + + + 1 + + + 1 + + + + + res\drawable-normal + 1 + + + + + res\drawable-xhdpi + 1 + + + + + res\drawable-large + 1 + + + + + 1 + + + 1 + + + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + ..\ + 1 + + + ..\ + 1 + + + + + res\drawable-hdpi + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + Contents + 1 + + + + + ..\ + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + 1 + + + 1 + + + 1 + + + + + res\values + 1 + + + + + res\drawable-small + 1 + + + + + res\drawable + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + + + res\drawable + 1 + + + + + 0 + + + 0 + + + Contents\Resources\StartUp\ + 0 + + + 0 + + + 0 + + + 0 + + + + + library\lib\armeabi-v7a + 1 + + + + + 0 + .bpl + + + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + + + res\drawable-mdpi + 1 + + + + + res\drawable-xlarge + 1 + + + + + res\drawable-ldpi + 1 + + + + + 1 + + + 1 + + + + + + + + + + + True False @@ -163,4 +586,5 @@ + diff --git a/samples/basicdemo_vclclient/Unit1.dfm b/samples/basicdemo_vclclient/Unit1.dfm index 63ee8d92..56a9291d 100644 --- a/samples/basicdemo_vclclient/Unit1.dfm +++ b/samples/basicdemo_vclclient/Unit1.dfm @@ -29,4 +29,13 @@ object Form1: TForm1 TabOrder = 0 OnClick = Button1Click end + object Button2: TButton + Left = 8 + Top = 144 + Width = 117 + Height = 25 + Caption = 'Unicode test' + TabOrder = 1 + OnClick = Button2Click + end end diff --git a/samples/basicdemo_vclclient/Unit1.pas b/samples/basicdemo_vclclient/Unit1.pas index d49e2624..f41d19ef 100644 --- a/samples/basicdemo_vclclient/Unit1.pas +++ b/samples/basicdemo_vclclient/Unit1.pas @@ -10,7 +10,9 @@ type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; + Button2: TButton; procedure Button1Click(Sender: TObject); + procedure Button2Click(Sender: TObject); private { Private-Deklarationen } public @@ -27,18 +29,31 @@ uses {$R *.dfm} + procedure TForm1.Button1Click(Sender: TObject); var Clt: TRestClient; begin - Clt := MVCFramework.RESTClient.TRESTClient.Create('http://localhost', 3000, nil); + Clt := MVCFramework.RESTClient.TRestClient.Create('http://localhost', 3000, nil); try -// Clt.ProxyServer := 'localhost'; -// Clt.ProxyPort := 8888; + // Clt.ProxyServer := 'localhost'; + // Clt.ProxyPort := 8888; ShowMessage(Clt.doGET('/div/10/20', []).BodyAsString); finally Clt.Free; end; end; +procedure TForm1.Button2Click(Sender: TObject); +var + Clt: TRestClient; +begin + Clt := MVCFramework.RESTClient.TRestClient.Create('http://localhost', 3000, nil); + try + ShowMessage(Clt.doPOST('/hello', [], '{"name":"Bob äöüß"}').BodyAsString); + finally + Clt.Free; + end; +end; + end. diff --git a/sources/MVCFramework.RESTClient.pas b/sources/MVCFramework.RESTClient.pas index 2beca84a..ab8a6a60 100644 --- a/sources/MVCFramework.RESTClient.pas +++ b/sources/MVCFramework.RESTClient.pas @@ -425,8 +425,8 @@ var ss: TStringStream; begin if (FContentEncoding = '') then - FContentEncoding := 'UTF-8'; - ss := TStringStream.Create('', TEncoding.GetEncoding(FContentEncoding)); + FContentEncoding := 'utf-8'; + ss := TStringStream.Create('', TEncoding.GetEncoding(FContentEncoding.ToLower)); try FBody.Position := 0; FBody.SaveToStream(ss); @@ -1055,7 +1055,7 @@ end; function TRESTClient.doPOST(const AResource: string; const AParams: array of string; const ABody: string): IRESTResponse; var - URL, lContentTypeWithCharset: string; + URL {, lContentTypeWithCharset}: string; begin URL := FProtocol + '://' + FHost + ':' + IntToStr(FPort) + AResource + EncodeResourceParams(AParams) + EncodeQueryStringParams(QueryStringParams); @@ -1067,10 +1067,10 @@ begin end else begin - lContentTypeWithCharset := FContentType; - if FContentEncoding = '' then - FContentEncoding := 'UTF-8'; - lContentTypeWithCharset := FContentType + ';charset=' + FContentEncoding; +// lContentTypeWithCharset := FContentType; +// if FContentEncoding = '' then +// FContentEncoding := 'UTF-8'; +// lContentTypeWithCharset := FContentType + ';charset=' + FContentEncoding; Result := SendHTTPCommandWithBody(httpPOST, FAccept, FContentType, FContentEncoding, URL, ABody); @@ -1562,18 +1562,22 @@ begin lContentEncoding := AContentEncoding; lContentTypeWithCharset := AContentType + ';charset=' + FContentEncoding; - FHTTP.Request.ContentType := lContentTypeWithCharset; + // FHTTP.Request.ContentType := lContentTypeWithCharset; + FHTTP.Request.ContentType := AContentType; FHTTP.Request.ContentEncoding := AContentEncoding; HandleRequestCookies; try + if FHTTP.Request.CharSet = '' then + FHTTP.Request.CharSet := 'utf-8'; + case ACommand of httpGET: begin FHTTP.Get(AResource, Result.Body); end; - httpPOST: + httpPOST, httpPUT: begin if (MultiPartFormData.Size <> 0) then raise ERESTClientException.Create('This method cannot send files'); @@ -1581,23 +1585,19 @@ begin RawBody.Position := 0; RawBody.Size := 0; -{$WARNINGS OFF} - if (LowerCase(FHTTP.Request.CharSet) = 'utf-8') then - RawBody.WriteString(UTF8ToString(ABody)) - else - begin - lEncoding := TEncoding.GetEncoding(FHTTP.Request.CharSet); - try - lBytes := TEncoding.Convert(TEncoding.Default, lEncoding, - TEncoding.Default.GetBytes(ABody)); - RawBody.WriteData(lBytes, Length(lBytes)); - finally - lEncoding.Free; - end; + lEncoding := TEncoding.GetEncoding(FHTTP.Request.CharSet); + try + lBytes := TEncoding.Convert(TEncoding.Default, lEncoding, + TEncoding.Default.GetBytes(ABody)); + RawBody.WriteData(lBytes, Length(lBytes)); + finally + lEncoding.Free; end; -{$WARNINGS ON} - FHTTP.Post(AResource, RawBody, Result.Body); + if ACommand = httpPOST then + FHTTP.Post(AResource, RawBody, Result.Body) + else + FHTTP.Put(AResource, RawBody, Result.Body); end; httpPATCH: @@ -1606,20 +1606,21 @@ begin ('Sorry, PATCH is not supported by the RESTClient because is not supportd by the TidHTTP'); end; - httpPUT: - begin - RawBody.Position := 0; - RawBody.Size := 0; - -{$WARNINGS OFF} - if (LowerCase(FHTTP.Request.CharSet) = 'utf-8') then - RawBody.WriteString(UTF8ToString(ABody)) - else - RawBody.WriteString(ABody); - -{$WARNINGS ON} - FHTTP.Put(AResource, RawBody, Result.Body); - end; +// httpPUT: +// begin +// RawBody.Position := 0; +// RawBody.Size := 0; +// lEncoding := TEncoding.GetEncoding(FHTTP.Request.CharSet); +// try +// lBytes := TEncoding.Convert(TEncoding.Default, lEncoding, +// TEncoding.Default.GetBytes(ABody)); +// RawBody.WriteData(lBytes, Length(lBytes)); +// finally +// lEncoding.Free; +// end; +// +// FHTTP.Put(AResource, RawBody, Result.Body); +// end; httpDELETE: begin diff --git a/unittests/TestServer/TestServer.dproj b/unittests/TestServer/TestServer.dproj index f4d714d9..84e00435 100644 --- a/unittests/TestServer/TestServer.dproj +++ b/unittests/TestServer/TestServer.dproj @@ -199,16 +199,7 @@ true - - - 0 - .dll;.bpl - - - 1 - .dylib - - + Contents\Resources @@ -548,7 +539,16 @@ 1 - + + + 0 + .dll;.bpl + + + 1 + .dylib + +