

mazluta
Members-
Content Count
39 -
Joined
-
Last visited
Everything posted by mazluta
-
PDF File Send as Base64 from c# to Delphi REST
mazluta replied to mazluta's topic in Network, Cloud and Web
Hi Remy Lebeau i think your answer is the right answer. this is the C# Code private void button1_Click(object sender, EventArgs e) { string requestUrl = "http://185.185.135.XXX:YYYY/MyTest"; HttpWebRequest request = HttpWebRequest.CreateHttp(requestUrl); request.Method = "POST"; // Optionally, set properties of the HttpWebRequest, such as: request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; request.ContentType = "application/x-www-form-urlencoded"; // Could also set other HTTP headers such as Request.UserAgent, Request.Referer, // Request.Accept, or other headers via the Request.Headers collection. //Byte[] fileBytes = File.ReadAllBytes(@textBox1.Text, System.Text.Encoding.ASCII); Byte[] fileBytes = File.ReadAllBytes(@textBox1.Text); var content = Convert.ToBase64String(fileBytes,Base64FormattingOptions.None); // Set the POST request body data. In this example, the POST data is in // application/x-www-form-urlencoded format. string postData = "DevApp=C#&Base64Type=base64&username=mazluta&base64=" + content; using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(postData); } // Submit the request, and get the response body from the remote server. string responseFromRemoteServer; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { responseFromRemoteServer = reader.ReadToEnd(); fileBytes = Convert.FromBase64String(responseFromRemoteServer); File.WriteAllBytes(@"c:\a\mytest.pdf", fileBytes); MessageBox.Show("File c:\\a\\mytest.pdf signed and saved"); } } } This is The Delphi Rest Code : procedure TMyWebModule.MyWebModuleactSignAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); Var RequestObject: TJSONObject; PdfBase64 : string; RspBase64 : string; UserName : string; Base64Type : string; DevApp : string; CachPdfPath : String; CachFilesPath : String; TmpPdfFile : String; TmpTxtFile : String; DstPdfFileName : String; SignParam : TSignParam; PfxFileName : String; PfxPassword : String; UserDataRec : TUserDataRec; ParamArea : TParamArea; UserSignData : TUserSignData; //aPdfBase64 : AnsiString; aRspBase64 : PAnsiChar; aTmpPdfFile : AnsiString; aTmpTxtFile : AnsiString; SaveTextList : TStringList; MyBytesArr : TBytes; CurChar : Integer; begin ( JustWriteToLog(' '); JustWriteToLog('======'); JustWriteToLog('reqeust=base64 at : ' + formatdatetime('dd/mm/yyyy hh:nn:ss:zzz', now)); JustWriteToLog(' '); UserName := Request.ContentFields.Values['UserName']; Base64Type := Request.ContentFields.Values['Base64Type']; PdfBase64 := Request.ContentFields.Values['Base64']; DevApp := Request.ContentFields.Values['DevApp']; JustWriteToLog(' '); JustWriteToLog('UserName='+UserName); JustWriteToLog(' '); JustWriteToLog('Base64Type='+Base64Type); JustWriteToLog(' '); JustWriteToLog('DevApp='+DevApp); JustWriteToLog(' '); JustWriteToLog('Base64='+PdfBase64); JustWriteToLog(' '); UserDataRec := dm_DB.GetUserData(UserName); ParamArea := dm_DB.LoadAppParams; JustWriteToLog('User request = ' + UserName); JustWriteToLog('Start PDF 50 char = ' + Copy(PdfBase64, 1, 50)); if UserDataRec.Found then JustWriteToLog('User Found') else JustWriteToLog('User not found'); if ParamArea.Found then JustWriteToLog('ParamArea Record found'); If not ParamArea.Found Then begin Response.Content := 'Fail load Server params'; Response.StatusCode := 400; exit; end; UserSignData := dm_DB.GetUserSignRec(UserDataRec, ParamArea); If not UserSignData.Found Then begin Response.Content := 'Fail load UserSignData params'; Response.StatusCode := 400; exit; end; JustWriteToLog('Find User SignData, PfxFile = ' + UserSignData.User_PfxFileName); JustWriteToLog('Find User SignData, LogoFile = ' + UserSignData.User_LogoFileName); CachPdfPath := GetBaseAppPath + '\' + DSHTTPWebDispatcher1.CacheContext; if CachPdfPath[length(CachPdfPath)] = '/' Then CachPdfPath[length(CachPdfPath)] := ' '; CachPdfPath := Trim(CachPdfPath); ForceDirectories(CachPdfPath); Try TmpPdfFile := CachPdfPath + '\Tmp_' + GetRandomStr + '.pdf'; TmpTxtFile := ChangeFileExt(TmpPdfFile,'.txt'); if UpperCase(DevApp) = UpperCase('C#') then begin JustWriteToLog('Before Replace PdfBase64 : ' + PdfBase64); SetLength(MyBytesArr,Length(PdfBase64)); MyBytesArr := TEncoding.ASCII.GetBytes(PdfBase64); for CurChar := 1 to Length(PdfBase64) do begin if Ord(MyBytesArr[CurChar]) = 32 then MyBytesArr[CurChar] := byte(43); end; PdfBase64 := TEncoding.ASCII.GetString(MyBytesArr); JustWriteToLog('After Replace PdfBase64 : ' + PdfBase64); ConvertBase64ToPdfFile(PdfBase64,TmpPdfFile); end else if UpperCase(Base64Type) = UpperCase('Base64') then begin ConvertBase64ToPdfFile(PdfBase64,TmpPdfFile); end else begin ConvertBase64MimeToPdfFile(PdfBase64,TmpPdfFile); end; JustWriteToLog('PDF File : ' + TmpPdfFile + ' Saved'); Except on e: exception do begin JustWriteToLog('Error on Save PDF File : ' + e.Message); Response.StatusCode := 390; Exit; end; End; DstPdfFileName := CachPdfPath + '\Rslt_' + GetRandomStr + '.pdf'; CachFilesPath := GetBaseAppPath + '\Files'; so - it looks that when I read the value of the Base64 field - the + becomes space PdfBase64 := Request.ContentFields.Values['Base64']; -
Hi, I use this DLL and it give good support and good documentation + examples
-
PDF File Send as Base64 from c# to Delphi REST
mazluta replied to mazluta's topic in Network, Cloud and Web
Hi mvanrijnen i dont think it's the CRLF. The + sign is replace with the Space sign (43 --> 32) -
PDF File Send as Base64 from c# to Delphi REST
mazluta replied to mazluta's topic in Network, Cloud and Web
Hi Remy I Could not figure out how to Send binary data from C# to Delphi REST? -
PDF File Send as Base64 from c# to Delphi REST
mazluta replied to mazluta's topic in Network, Cloud and Web
Ok, it looks like I figured it out. but I am not sure it works for every c# version 🙂 (can't trust Windows developer). The Base64FormattingOptions_None.txt file contains the text of base64 created in C# before sending it to Delphi Rest. The ThisWhatDelphiRestGet.txt file contains the base64 text that Delphi rest moves to my var after Http Request envoke. The LogBase64Different.txt contains the differences Including Char No# and The Char ItSelf. It looks like DELPHI REST replaced the ASCII 43 to 32 or the HTTP request of the C# sent ASCII 32 instead of ASCII 43. So, If The Request comes from C#, I just convert all appearances of ASCII char 32 to 43, then save The PDF, and all work. SetLength(MyBytesArr,Length(PdfBase64)); MyBytesArr := TEncoding.ASCII.GetBytes(PdfBase64); for CurChar := 1 to Length(PdfBase64) do begin if Ord(MyBytesArr[CurChar]) = 32 then MyBytesArr[CurChar] := byte(43); end; PdfBase64 := TEncoding.ASCII.GetString(MyBytesArr); Can I Trust That Solution? Or I Missed Something? Thanks, Yossi Base64FormattingOptions_None.txt ThisWhatDelphiRestGet.txt LogBase64Different.txt -
PDF File Send as Base64 from c# to Delphi REST
mazluta replied to mazluta's topic in Network, Cloud and Web
He remy. 1. I will prepare a text file that holds what c# sends and what Delphi Rest reads. 2. how do I send PDF as binary data from C# to Delphi Rest? 3. dose it matter if the C# is AnyCPU or X64 and the rest is x86? Thanks, Yossi -
i just create rest service with authoticate entry. the default login form look like this : how can i change the login form as i want and control the form shape? lables, headers, positions
- 10 replies
-
How do i control the Login Form shape of Datasnap Rest Service
mazluta replied to mazluta's topic in VCL
well programmer..2k. that work. thanls b.t.w you are not so selfishness- 10 replies
-
How do i control the Login Form shape of Datasnap Rest Service
mazluta replied to mazluta's topic in VCL
thanks. i will try it- 10 replies
-
How do i control the Login Form shape of Datasnap Rest Service
mazluta replied to mazluta's topic in VCL
".....customization can be done on events before send to client, or using a frameworks (3rd) like done by Intraweb, UniGui, etc... ....." can i write Web Service with UNIGUI ?- 10 replies
-
How do i control the Login Form shape of Datasnap Rest Service
mazluta replied to mazluta's topic in VCL
I just want the Login form to look like this :- 10 replies
-
How do i control the Login Form shape of Datasnap Rest Service
mazluta replied to mazluta's topic in VCL
first, thanks. I use my rest to get a PDF file as base64, a digital sign with some digital certificate. based on the user's table I want to popup him with the login form. but I don't want him to see the "Server Function.." label.- 10 replies
-
hi. i have this algorithm the web app witen with unigui. the web service writen with delphi using webbroker. when i run the app in my local machine and run the web app from the browser it talks to the web service as should. when i run the app from the cloud, the browser says: what do i miss?
-
Hi mjustin first thanks. even if the FireWall is down it does not working. when i run the site from the browser from "local site" like localhost:8077 it work when i run from hanibaaldemos.com:8077 then it fails to locate the WebService in my local host