You are not logged in.
Ctxt.OutCustomHeaders := Ctxt.OutCustomHeaders + #13#10+ 'Set-Cookie: a=1111111111; b=22222222';
with this code, just get the first one, 'b=22222222' is still missing.
hi,ab
i need to set more than one cookie key/value, but just the last one will be sent to the client. the code is as follow:
Ctxt.OutCustomHeaders := Ctxt.OutCustomHeaders + #13#10+
'Set-Cookie: a=1111111111' + #13#10 + 'Set-Cookie: b=22222222';in the client response header, just get 'Set-Cookie: b=22222222'' string, and 'Set-Cookie: a=1111111111' is missing.
thanks!
That is what I did.
DWS has a sample "HttpSys2WebServer", it used TWebRequest/TWebResponse parameters for FDWS.HandleDWS procedure, that is why I asked you how to prepare TWebRequest from THttpServerRequest.
It will be great if THttpServerRequest provides the TWebRequest information.
The 2nd option would be preferred, and I would like to get started with it.
I planned to script it in the onrequest procedure of mORMot server, or should I use the WebSocket?
Many thanks.
ab, Could you include TWebRequest item in THttpServerRequest?
i got it, in Delphi XE7, just as follow:
procedure TForm1.utf8ansiClick(Sender: TObject);
var
sl:TStringlist;
aa:tbytes;
begin
sl:=TStringlist.Create;
sl.LoadFromFile('c:\1.txt');
Memo1.Lines.Add(sl.Text);
aa := TEnCoding.UTF8.GetBytes(sl.Text);
e1.Text := StringOf(aa);
e2.Text := TEnCoding.utf8.GetString(aa);
......
end;thanks,ab.
perhaps it is the difference between delphi XE7 and delphi 7, i try to understand it.
sorry for my english,ab.
i know how to get remoteip from CallContext, but don't know how to assign it to TWebRequest. ![]()
TWebRequest = class
private
FCookies : TStrings;
FQueryFields : TStrings;
FContentFields : TStrings;
FCustom : TObject;
protected
FPathInfo : String;
FQueryString : String;
function GetHeaders : TStrings; virtual; abstract;
function GetCookies : TStrings;
function GetQueryFields : TStrings;
function GetContentFields : TStrings;
function GetUserAgent : String;
function GetAuthentication : TWebRequestAuthentication; virtual;
function GetAuthenticatedUser : String; virtual;
function PrepareCookies : TStrings; virtual;
function PrepareQueryFields : TStrings; virtual;
function PrepareContentFields : TStrings; virtual;
public
constructor Create;
destructor Destroy; override;
procedure ResetCookies; inline;
procedure ResetQueryFields; inline;
procedure ResetContentFields; inline;
procedure ResetFields; inline;
function Header(const headerName : String) : String;
function RemoteIP : String; virtual; abstract;
function RawURL : RawByteString; virtual; abstract;
function URL : String; virtual; abstract;
function Method : String; virtual; abstract;
function MethodVerb : TWebRequestMethodVerb; virtual; abstract;
function Security : String; virtual;
function ContentData : RawByteString; virtual; abstract;
function ContentType : RawByteString; virtual; abstract;
property PathInfo : String read FPathInfo write FPathInfo;
property QueryString : String read FQueryString write FQueryString;
property UserAgent : String read GetUserAgent;
property Headers : TStrings read GetHeaders;
property Cookies : TStrings read GetCookies;
property QueryFields : TStrings read GetQueryFields;
property ContentFields : TStrings read GetContentFields;
function HasQueryField(const name : String) : Boolean;
function HasContentField(const name : String) : Boolean;
function IfModifiedSince : TDateTime;
property Authentication : TWebRequestAuthentication read GetAuthentication;
property AuthenticatedUser : String read GetAuthenticatedUser;
// custom object field, freed with the request
property Custom : TObject read FCustom write FCustom;
end;TWebRequest above is defined in dwsWebEnvironment.pas of DWS package, i can create an instanc as follow:
WebRequest := TWebRequest.create;and how could i assign the value to WebRequest.RemoteIP...?
i did, i used THttpServerRequest in my mORMotHttpServer server. but FDWS.HandleDWS should handle TWebRequest/TWebResponse parameters.
i am thinking about to use DWS within mORMot Framework.
in sample "HttpSys2WebServer", procedure "FDWS.HandleDWS" used TWebRequest and TWebResponse as parameters, but how to translate THttpServerRequest to TWebRequest in my server?
thanks.
everything is ok under delphi 7.
under delphi XE7, function DataSetToJSON got the expected result also if not including chinese words.
i found that under delphi XE7 and delphi 7, function stringtoutf8 got different result with the same source string including chinese words.
i just use XE7 from Delphi7, and the chinese words from database are also abnormal with function DataSetToJSON in SynVirtualDataSet.pas.
祝大家圣诞节快乐!
My field data type is varchar(255) with utf8-bin charset in mysql, and i use TZReadOnlyQuery of Zeoslib to query data from mysql, then call DataSetToJSON to get JSON data, so i don't know where to define the field as ftWideString, and not ftString.
Should i define UNICODE in Synopse.inc?
Thanks.
i use delphi7 and mysql, DB charset is UTF-8.
but it is meaningful for me
.
if i changed the code above, i always got the right data including chinese words from database, or sometimes broken data.
it is a ftString, ftFixedChar or ftMemo one, like this:
ftString, ftFixedChar, ftMemo: begin
W.Add('"');
W.AddAnsiString({$ifdef UNICODE}AsAnsiString{$else}AsString{$endif},
twJSONEscape);
W.Add('"');
end;if define UNICODE, should use W.AddAnsiString for AsAnsiString, else W.AddString for AsString, as follow:
ftString, ftFixedChar, ftMemo: begin
W.Add('"');
{$ifdef UNICODE}
W.AddAnsiString(AsAnsiString,twJSONEscape);
{$else}
W.AddString(AsString);
{$endif}
W.Add('"');
end;hi,ab
i think that the following code of function DataSetToJSON in SynVirtualDataSet.pas
W.AddAnsiString({$ifdef UNICODE}AsAnsiString{$else}AsString{$endif},
twJSONEscape);should be
{$ifdef UNICODE}
W.AddAnsiString(AsAnsiString,twJSONEscape);
{$else}
W.AddString(AsString);
{$endif}got it.
after a little while, without request, the memory usage of server will decrease.
thanks again.
you are absolutely right, after certain of requests the memory usage is not continue increasing.
and thank you so much.
it is strange, and it really bothers me for a little while.
please note that i just post data to server from client, and the server did not handle the data at all.
it seems that the server will be attacked by continuing data whatever the client postes.
i used the latest version, and i enabled EnableMemoryLeakReporting, but no memory leak reported.
i did it because i need to post data from browser, but REST methord can not be used in browser as usual .
i compiled "13 - StandAlone JSON SQL server" without changing any thing, and run the JSONSQLServer.exe, then used the code below to post data to the server, not post of REST, but post of URL, the memory of server kept increasing after each data was posted to the server.
procedure TForm8.Button11Click(Sender: TObject);
var
tmpstream:TMemoryStream;
ab:boolean;
HTTP: THTTPSend;
url:string;
slist:TStringlist;
begin
tmpstream := TMemoryStream.Create;
HTTP := THTTPSend.Create;
slist:=TStringlist.Create;
try
url := 'http://localhost:888/root';
tmpstream.LoadFromFile('c:\rtl70.bpl');
tmpstream.Position := 0;
ab := HttpPostFile(url,'abc','def',tmpstream,slist);
... ...
finally
tmpstream.Free;
HTTP.Free;
slist.free;
end;
end;many thanks to all of you.
but i have another issue:
the memory of server kept increasing after each Binary Data was posted to the server, even if the server did not handle it at all.
using sample SymmetricCrypto from http://www.torry.net/vcl/security/stron … boxvcl.zip, i got the same result "C97554911E393C5CF451FA5B0C1F3F7B", but i prefer to use syncrypto.
thanks.
with SynCrypto:
plaintext:123456
key:1234567890123456
result:BBB958B46D43174355EBBCACDDE1A171
is the result above correct with PKCS#7?
Could you add a function as EncryptPKCS5?
i just want them to get the same result "C97554911E393C5CF451FA5B0C1F3F7B" to work together.
i use delphi 7, but i can not get the result: C97554911E393C5CF451FA5B0C1F3F7B.
i used SynCrypto to encrypt plaintext with aes/ecb/PKCS7padding, but the encrypted text was different from the one encrypted using Wcrypt2 from http://delphi-jedi.org.
i need the encrypted text could be used by php, but i can not manage it.
here is my code:
function EncryptMsgData(MsgData, Key: string): string;
var
i:integer;
ECB:TAESECB;
iv:TAESBlock;
begin
Result:= '';
for i:=0 to 15 do
begin
if i > (length(Key) - 1) then
iv[i] := 0
else
iv[i] := byte(Key[i + 1]);
end;
try
ECB := TAESECB.Create(Key,128,iv);
result := ECB.EncryptPKCS7(MsgData);
finally
ECB.Free;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
CText.Text := strtohex(EncryptMsgData('123456','1234567890123456'));
end;with SynCrypto:
plaintext:123456
key:1234567890123456
result:BBB958B46D43174355EBBCACDDE1A171
with wcrypt2(aes/ecb/PKCS5padding)
plaintext:123456
key:1234567890123456
result:C97554911E393C5CF451FA5B0C1F3F7B
by the way, how to create TAESECB from SynCrypto without IV, and function EncryptPKCS5 is missing.
thanks.
thanks, after i recompile all units, it works now.
by the way, mORMots are really great, and do run fast...
thanks again.
yes, i am using the latest version, and the Client instance class is TSQLRestClientURI defined as follow:
Client:TSQLRestClientURI;
i just call it on windows 2003 server , it is ok.
the following call works fine on windows xp and win7, but it crashed on windows 2008 server:
TSQLHttpClient(Client).CallBackPut('rpcname',RUTF8,rtnutf8); the actually position is in TSQLRestClientURI.URI of mORMot.pas as follow:
......
DoRetry:
if fSessionAuthentication=nil then
Call.Url := url else
Call.Url := fSessionAuthentication.ClientSessionSign(self,url);
Call.Method := method;
if SendData<>nil then
Call.InBody := SendData^;
{$ifndef LVCL}
if Assigned(fOnIdle) then begin
if fBackgroundThread=nil then
fBackgroundThread := TSynBackgroundThreadEvent.Create(OnIdle,OnBackgroundProcess);
if not fBackgroundThread.AsynchRun(@Call) then
Call.OutStatus := HTML_UNAVAILABLE;
end else
{$endif}
begin
InternalURI(Call); <<------------- crashed here
if Call.OutStatus=HTML_NOTIMPLEMENTED then begin // InternalCheckOpen failed
InternalClose; // force recreate connection
InternalURI(Call); // try request again
end;
end;
result.Lo := Call.OutStatus;
result.Hi := Call.OutInternalState;
if Head<>nil then
Head^ := Call.OutHead;
if Resp<>nil then
Resp^ := Call.OutBody;
fLastErrorCode := Call.OutStatus;
if (Call.OutStatus=HTML_TIMEOUT) and aRetryOnceOnTimeout then begin
aRetryOnceOnTimeout := false;
{$ifdef WITHLOG}
SQLite3Log.Add.Log(sllError,'% % returned "408 Request Timeout" -> RETRY',
[method,url],self);
{$endif}
goto DoRetry;
end;
......fScaleY is always 0.75
font.LogFont.lfHeight < 0
font.spec.cell = abs(font.LogFont.lfHeight)
as follow:
ASize font.LogFont.lfHeight font.spec.cell
------------------------------------------
87.75,-117,117
87.75,-117,117
87.75,-117,117
87.75,-117,117
75,-100,100
75,-100,100
75,-100,100
75,-100,100
87.75,-117,117
87.75,-117,117
87.75,-117,117
87.75,-117,117
87.75,-117,117
87.75,-117,117
87.75,-117,117
87.75,-117,117
87.75,-117,117
87.75,-117,117
87.75,-117,117
75,-100,100
75,-100,100
75,-100,100
75,-100,100
87.75,-117,117
87.75,-117,117
87.75,-117,117
......
but i am not sure which one is not correct.
in procedure TPdfEnum.TextOut(var R: TEMRExtTextOut) of SynPdf.pas, the following code:
if font.LogFont.lfHeight<0 then
ASize := Abs(font.LogFont.lfHeight)*fscaleY else
ASize := Abs(font.spec.cell)*fscaleY;the value of ASize ,sometimes is 66, sometimes is 4.27450962518871E-39, i guess ASize is not correct sometimes.
the font name is "宋体" in chinese.
i use delphi7 and the latest great mORMot.
thanks.
i change line 5827 of synpdf.pas
from:
RawUnicodeToUtf8(ALogFont.lfFaceName,StrLenW(ALogFont.lfFaceName));
to:
AName := ALogFont.lfFaceName;
then the following code can render emf file including all chinese words into pdf file:
procedure TForm1.Button6Click(Sender: TObject);
var
emf : TMetafile;
Pdf: TPdfDocument;
begin
emf := TMetafile.Create;
Pdf := TPdfDocument.Create;
try
emf.LoadFromFile('c:\emf\21.emf');
Pdf.EmbeddedTTF := True;
pdf.StandardFontsReplace := true;
pdf.PDFA1 := true;
Pdf.UseFontFallBack := true;
Pdf.FontFallBackName := 'Arial Unicode MS';
Pdf.DefaultPageWidth := MulDiv(emf.Width,72,Pdf.ScreenLogPixels);
Pdf.DefaultPageHeight := MulDiv(emf.Height,72,Pdf.ScreenLogPixels);
Pdf.AddPage;
Pdf.Canvas.RenderMetaFile(emf);
pdf.SaveToFile('c:\emf\test.pdf');
finally
FreeAndNil(emf);
FreeAndNil(pdf);
end;
end;but the position and size of some words are unusual.
i sent an email with "pdf from emf.jpg" and "emf21.emf" to webcontact01 at synopse.info, please check it.
i use htm2pdf in the latest package from http://synopse.info/fossil/wiki/Synopse+OpenSource, and open a html file with chinese words, then save html file to pdf file, the chinese words are still missing in the output pdf file, but the metafile produced by htmlview contains all things in the html file.
could you give me a sample, many thanks.
DrawAntiAliased in SynGdiPlus.pas is like this:
procedure TGDIPlus.DrawAntiAliased(Source: TMetafile; Dest: HDC; R: TRect;
aSmoothing: TSmoothingMode; aTextRendering: TTextRenderingHint);
begin
dec(R.Right);
dec(R.Bottom); // Metafile rect includes right and bottom coords
PlayEnhMetaFile(Dest,Source.Handle,R); // use GDI drawing by default
end;but PlayEnhMetaFile is a windows function, i can not step in it.
i download ARIALUNI.TTF from http://anonym.to/?http://sourceforge.ne … nts/files/, and then set FontFallBackName like this:
PdfDoc.FontFallBackName := 'Arial Unicode MS';the chinese words are still missing.
i also download synpdfunicode_test.rar from https://cdn.anonfiles.com/1363978013590.rar , and it works as expected.
BTW,i am using the latest code.
procedure TForm1.Button3Click(Sender: TObject);
var
Gdip:TGDIPlusFull;
emf:TMetaFile;
begin
Gdip := TGDIPlusFull.Create;
emf := TMetaFile.Create;
try
emf.LoadFromFile('c:\emf\1.emf');
gdip.DrawAntiAliased(emf,PaintBox1.Canvas.Handle,Rect(0,0,300,500));
finally
emf.Free;
Gdip.Free;
end;
end;PaintBox1 can display all of the emf file including chinese words and bitmap.
if i change above code as the following, the produced pdf file just contains bitmap,but no chinese words at all.
procedure TForm1.Button2Click(Sender: TObject);
const
OutputFileName = 'c:\emf\1.pdf';
InputFileName = 'c:\emf\1.emf';
var
PdfDoc: TPDFDocumentGDI;
PdfPage: TPdfpage;
Emf: TMetafile;
begin
Emf := TMetafile.Create();
Emf.LoadFromFile(InputFileName);
PdfDoc := TPdfDocumentGDI.Create;
PdfDoc.UseFontFallBack := true;
PdfDoc.CompressionMethod := cmFlateDecode;
PdfDoc.DefaultPaperSize := psUserDefined;
PdfPage := PdfDoc.AddPage();
PdfPage.PageWidth := Round(72 * Emf.MMWidth / 2540);
PdfPage.PageHeight := Round(72 * Emf.MMHeight / 2540);
gdip.DrawAntiAliased(emf,PdfDoc.VCLCanvas.Handle,Rect(0, 0,
//gdip.DrawAntiAliased(emf,PaintBox1.Canvas.Handle,Rect(0, 0,
Round(Screen.PixelsPerInch * Emf.MMWidth / 2540),
Round(Screen.PixelsPerInch * Emf.MMHeight / 2540)));
PdfDoc.SaveToFile(OutputFileName);
PdfDoc.Free();
FreeAndNil(Emf);
end;absolutely, i tried the latest versions, no error message popuped, but no chinese words displayed in pdf file.
now, i use adobe virtual printer and ghostscript to produce pdf files from doc files, but it is so complicated, and ghostscript file is too big to install.
thanks, and i is a bad news for me.
see http://synopse.info/forum/viewtopic.php?id=42, i can generate correct emf files from doc file using adobe virtual printer, but i still can not translate the emf files into pdf file using synpdf, because the chinese fonts are unusual.
i noticed http://synopse.info/fossil/info/4f99e33ea0 just before, and i compiled SynProject, and it worked fine.
i use win7 + office2007 + 2007 Microsoft Office Add-in: Microsoft Save as PDF or XPS in my computer, but i copied SynProject.exe to another computer with win7 + office2007 only, it did not work, error mesage was "Error during the document creation. Did'nt you miss a \ or a } in your text?".
is it necessary to install 2007 Microsoft Office Add-in to export the SAD document as pdf? indeed, i need save ms document file as emf, pdf or swf file directly without Add-in.
thanks.
sorry,i made a mistake.
i should parse the post data before call urldecode.
thanks, ab.
i parsed it using "&" as Delimiter,so i got the result as follow:
var1 = value1
var2 = a.php?varphp1=valuephp1
varphp2 = valuephp2
var3 = value3
but it is not what i need.