You are not logged in.
using IE browser to post data to my server, i get a post data in Variable "InContent" as follow:
var1=value1&var2=a.php?varphp1=valuephp1&varphp2=valuephp2&var3=value3
the result i parsed as follow:
var1 = value1
var2 = a.php?varphp1=valuephp1
varphp2 = valuephp2
var3 = value3
but what i really need is:
var1 = value1
var2 = a.php?varphp1=valuephp1&varphp2=valuephp2
var3 = value3
the apache server can parse it correctly.
what should i do, thanks.
u are right, and i got it.
many thanks.
yes, what i mean is that it returns false when i get the last 500 bytes,
the syntax is right just like above standard,because the previous segments are all correct.
sorry,678 means the rang length,so i mean 12345,12345 + 678.
thanks, and it s great.
another problem i can not understand is:
i download a file from server using many segments, the range of the last segment perhaps is 12345,678.
if i download the last segment with range of 12345,678, it returns fales, but if i use 12345,-1, it is ok.
BTW,it s terrific about http://blog.synopse.info/post/2012/09/0 … laboration
procedure THttpApiServer.Execute;
var Req: PHTTP_REQUEST;
ReqID: HTTP_REQUEST_ID;
ReqBuf, RespBuf: TSockData;
i: integer;
flags, bytesRead, bytesSent: cardinal;
Err: HRESULT;
InCompressAccept: THttpSocketCompressSet;
InContentLength, InContentLengthRead: cardinal;
InContentLengthStr: TSockData;
InContentEncoding, InAcceptEncoding: TSockData;
OutContentEncoding: TSockData;
InURL, InMethod, InHeaders, InContent, InContentType: TSockData;
OutContent, OutContentType, OutCustomHeader, OutStatus: TSockData;
OutContentTypeP: PAnsiChar absolute OutContentType;
FileHandle: THandle;
Resp: PHTTP_RESPONSE;
BufRead: PAnsiChar;
Heads: array of HTTP_UNKNOWN_HEADER;
DataChunk: HTTP_DATA_CHUNK;
rangstart,ranglength:int64;
procedure getrangstartend;
var
i,ipos:integer;
ssl:TStringlist;
tmpstr:string;
begin
rangstart := 0;
ranglength := -1;
if (trim(inHeaders) = '') then exit;
ssl := TStringlist.Create;
ssl.Text := inHeaders;
for i := 0 to ssl.Count -1 do
begin
tmpstr := trim(ssl.Strings[i]);
if (pos('range:',lowercase(tmpstr)) = 1) then
begin
tmpstr := trim(copy(tmpstr,7,length(tmpstr) - 6));
if (pos('bytes=',lowercase(tmpstr)) = 1) then
begin
tmpstr := trim(copy(tmpstr,7,length(tmpstr) - 6));
ipos := pos('-',tmpstr);
if (ipos > 0) then
begin
try
rangstart := strtoint64(trim(copy(tmpstr,1,ipos - 1)));
except
rangstart := 0;
end;
try
ranglength := strtoint64(trim(copy(tmpstr,ipos + 1,
length(tmpstr) - ipos + 1)));
except
ranglength := -1;
end;
if (ranglength > rangstart) then
ranglength := ranglength - rangstart
else
ranglength := -1;
end
else
begin
ranglength := -1;
try
rangstart := strtoint64(trim(tmpstr));
except
rangstart := 0;
end;
end;
end;
end;
end;
ssl.free;
end;
procedure SendError(StatusCode: cardinal; const ErrorMsg: string);
begin
Resp^.SetStatus(StatusCode,OutStatus,@DataChunk,TSockData(ErrorMsg));
Http.SendHttpResponse(fReqQueue,Req^.RequestId,0,Resp^,nil,bytesSent);
end;
begingetrangstartend is not so good ![]()
i got it...
here is the code i just modify:
if OutContentType=HTTP_RESP_STATICFILE then begin
// response is file -> let http.sys serve it (OutContent is UTF-8)
FileHandle := FileOpen(
{$ifdef UNICODE}UTF8ToUnicodeString{$else}Utf8ToAnsi{$endif}(OutContent),
fmOpenRead or fmShareDenyNone);
if PtrInt(FileHandle)<0 then
SendError(404,SysErrorMessage(GetLastError)) else
try
DataChunk.DataChunkType := hctFromFileHandle;
DataChunk.FromFileHandle.FileHandle := FileHandle;
rangstart := 0;
ranglength := -1;
getrangstartend;
DataChunk.FromFileHandle.ByteRange.StartingOffset.QuadPart := rangstart;
Int64(DataChunk.FromFileHandle.ByteRange.Length.QuadPart) := ranglength; // to eof
Resp^.EntityChunkCount := 1;
Resp^.pEntityChunks := @DataChunk;
Http.SendHttpResponse(fReqQueue,Req^.RequestId,1,Resp^,nil,bytesSent);
finally
FileClose(FileHandle);
end;
end else begingetrangstartend is used to get rangstart and ranglength from inHeaders.
the flags of Http.SendHttpResponse is changed to 1 from 0.
and it works now.
thanks,ab.
Here is what i m learning about: http://xxm.sourceforge.net/
Perhaps "hsys" of it is what i m looking for...
while using THttpApiServer, how to response part of file according to 'Range: bytes=***-***' in InHeaders?
thanks.
i sent an email including emf and pdf files to you last night,please check it.
i really appreciate.
with my own rtf and emf files, no exception raised any more,but:
1. in pdf file,no chinese word appears,if i switch to view this pdf document as text file,then all chinese words appear.
2. position of numeric word in the pdf is not exactally correct.
i send pdf files to you,pls check it: abouchez@magic.fr
yes, a big vague
,because i can not past picture or file here.
the exception line is:
Width := (cardinal(fhmtx[Glyph*2])*1000) shr fUnitsPerEmShr;
exception msg:
'Access violation at address 004626A7 in module 'Project1.exe'. Read of address 004B4000'
Are you sure the TTF file is a true outline font?
i m not sure,indeed.
i just try it,the chinese words of emf file are all generated into pdf file,but they can not display properly in pdf file.
during generate pdf file,some exceptions are fired near the following code of synpdf.pas:
constructor TPdfTTF.Create(aUnicodeTTF: TPdfFontTrueType);
......
for i := 0 to aUnicodeTTF.fUsedWideChar.Count-1 do
with aUnicodeTTF.fUsedWide[i] do
if Glyph<>0 then
Width := (cardinal(fhmtx[Glyph*2])*1000) shr fUnitsPerEmShr;u are the greatest.
i see, and i will check it.
thanks a lot.
here is my code refer syndb,
unit uzjsonquery;
interface
uses Classes,SysUtils, db,ZConnection,ZSqlProcessor,ZDataset,
SQLite3, SynCommons,syndb,synoledb,SQLite3Commons;
type
TZJsonQuery = class(TZQuery)
private
protected
procedure ColumnsToJSON(WR: TJSONWriter);
function FetchAllToJSON(JSON: TStream; Expanded: boolean): PtrInt;
public
function FetchAllAsJSON(Expanded: boolean; ReturnedRowCount: PPtrInt=nil): RawUTF8;
end;
implementation
procedure TZJsonQuery.ColumnsToJSON(WR: TJSONWriter);
var col: integer;
blob: RawByteString;
tmpstream:TMemoryStream;
begin
if WR.Expand then WR.Add('{');
for col := 0 to FieldCount - 1 do begin
if WR.Expand then
WR.AddFieldName(Fields[col].FieldName); // add '"ColumnName":'
if Fields[col].IsNull then
WR.AddShort('null') else
case Fields[col].DataType of
db.ftUnknown: WR.AddShort('null');
ftSmallint, ftInteger, ftWord,ftLargeint: WR.Add(Fields[col].AsInteger);
ftFloat:WR.Add(Fields[col].AsFloat);
db.ftCurrency: WR.AddCurr64(Fields[col].AsCurrency);
db.ftDate, db.ftTime, db.ftDateTime: begin
WR.Add('"');
WR.AddDateTime(Fields[col].AsDateTime);
WR.Add('"');
end;
ftMemo,ftstring,ftWideString: begin
WR.Add('"');
WR.AddJSONEscape(pointer(Fields[col].AsString));
WR.Add('"');
end;
db.ftBlob: begin
tmpstream := TMemoryStream.Create;
try
TBlobField(Fields[col]).SaveToStream(tmpstream);
tmpstream.Position := 0;
WR.WrBase64(tmpstream.Memory,tmpstream.Size,true);
finally
tmpstream.Free;
tmpstream := nil;
end;
end;
else raise ESQLDBException.CreateFmt('%s: Invalid ColumnType() %s',
[ClassName,'']);
end;
WR.Add(',');
end;
WR.CancelLastComma; // cancel last ','
if WR.Expand then WR.Add('}');
end;
function TZJsonQuery.FetchAllToJSON(JSON: TStream; Expanded: boolean): PtrInt;
var W: TJSONWriter;
col: integer;
begin
result := 0;
W := TJSONWriter.Create(JSON,Expanded,false);
try
SetLength(W.ColNames,FieldCount);//columncount
for col := 0 to FieldCount-1 do
W.ColNames[col] := FieldDefList.FieldDefs[col].Name;
W.AddColumns;
if Expanded then W.Add('[');
First;
while (not Eof) do
begin
ColumnsToJSON(W);
W.Add(',');
inc(result);
Next;
end;
W.CancelLastComma; // cancel last ','
W.Add(']');
if not Expanded then W.Add('}');
W.Add(#10);
W.Flush;
finally
W.Free;
end;
end;
function TZJsonQuery.FetchAllAsJSON(Expanded: boolean;
ReturnedRowCount: PPtrInt=nil): RawUTF8;
var Stream: TRawByteStringStream;
RowCount: PtrInt;
begin
Stream := TRawByteStringStream.Create;
try
RowCount := FetchAllToJSON(Stream,Expanded);
if ReturnedRowCount<>nil then ReturnedRowCount^ := RowCount;
result := Stream.DataString;
finally
Stream.Free;
end;
end;it is ok for me, and i hope it is usful for someone else.
while using ZeosLib,another question is about json:
how to translate between ZeosLib's Query and json?
i use sqlite3 and mysql at the same time.
and i used synpdf before,but it can not process chinese font from my emf file,so i pause now, and i shall pick up it later.
i post here before: http://synopse.info/forum/viewtopic.php?id=42
how long shall the SynDBODBC.pas be finished? is it sutable for my case?
i really want use less third commponent.
thanks again.
thanks,
perhaps i should use zeoslib at the server side as i used to.
i use HeidiSQL 5.0.0.3272 and execute 'select blobfield from mytable where id=100',it can return one row with blobfield content,no error displays.
ado and syndbexplorer are the same,
i try syndbexplorer ,if i use "select * from mytable where id = 100",it returns one row with the blobfield empty. if i use 'select blobfield from mytable where id=100',it makes a mistake and popup a error window. the error window just like this:
Error
OLEDB Error 80040E21 - ?? OLE DB
???????????,????? OLEDB ????????????
Exception class:EOleDBException
it does not work,and also returns nothing.
the OleDB Provider i use is:mysql-connector-odbc-5.1.11-win32.msi.
yes, it is a TEXT column,i use Query.ColumnUTF8(), and i also got nothing.
IMHO,Query.Execute('select blobfield from mytable where id=100',true) returns empty,
but 'select blobfield from mytable where id=100' does return one row.
if Query.Step then
aParams.Resp := Query.ColumnBlob(0)
else
// no rows return
i check that Query.Step returns false.
but,'select blobfield from mytable where id=100' does return one row, and "blobfield" is text type of Mysql.
i add step(true) or step(false) before "aParams.Resp := Query.ColumnBlob(0);",it is just the same problem.
i think 'select blobfield from mytable where id=100' makes the mistake,but it is really a correct SQL statement.
i retrieve blob data from database using TSQLDBStatement,but the Query.TotalRowsRetrieved is always zero:
var
OleDBConnectionProperties:TOleDBConnectionProperties;
SQLDBConnection:TSQLDBConnection;
Query: TSQLDBStatement;
......
OleDBConnectionProperties := TOleDBConnectionProperties.Create('','','','');
OleDBConnectionProperties.ConnectionString := myrdbmstr;
try
SQLDBConnection := OleDBConnectionProperties.NewConnection;
except
OleDBConnectionProperties.Free;
exit;
end;
try
Query := SQLDBConnection.NewStatement;
except
SQLDBConnection.Disconnect;
SQLDBConnection.Free;
OleDBConnectionProperties.Free;
exit;
end;
try
Query.Execute('select blobfield from mytable where id=100',true);
aParams.Resp := Query.ColumnBlob(0);
except
Query.Free;
SQLDBConnection.Disconnect;
SQLDBConnection.Free;
OleDBConnectionProperties.Free;
aParams.Resp := '';
exit;
end;thanks,ab,
it does work after using administrator user to run the service.
use the following connectionstring,it works in a service:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Administrator\Desktop\aa.mdb;Persist Security Info=False
BTW,with "Provider=MSDASQL.1;Persist Security Info=False;Data Source=mysource" connectionstring,i used "mysql-connector-odbc-5.1.11-win32" to connect mysql...
the following function can execute in a TForm ,but can not in a TService,why?
function execsql;
var
OleDBConnectionProperties:TOleDBConnectionProperties;
SQLDBConnection:TSQLDBConnection;
Query: TSQLDBStatement;
begin
result := false;
OleDBConnectionProperties := TOleDBConnectionProperties.Create('','','','');
OleDBConnectionProperties.ConnectionString := 'Provider=MSDASQL.1;Persist Security Info=False;Data Source=mysource';
SQLDBConnection := OleDBConnectionProperties.NewConnection;
Query := SQLDBConnection.NewStatement;
try
Query.Execute('insert into mytable(ccode) values(12345)',false);
except
Query.Free;
exit;
end;
Query.Free;
result := true;
end;i v got the exactly place of "hosting",and it is easy.
i mean it is not so easy to understand "hosting".
thanks again,and i will try once more...
thanks,
got the documentation,but it seems not a piece of cake.
hi,ab
how to make many servers separately work together?
thanks.
it s great,
BTW,i use TSQLRestServerStaticInMemory just for cache, for real database i also use TSQLRestServerDB...
many thanks for coblongpamor and ab.
dbcache := TSQLRestServerStaticInMemory.Create(TCache,nil,'');
......
lastcache := 60 * 1000;
tmpid := 1;
Rec := TCache.Create(dbcache, 'id=%',[tmpid]);
try
tmpid := Rec.ID;
cur64 := Rec.Time;
finally
Rec.Free;
end;
while (tmpid > 0) do
begin
if (cur64 < lastcache) then
begin
ab := dbcache.Delete(TCache,tmpid);
if (not ab) then break;
end else tmpid := tmpid + 1;
Rec := TCache.Create(dbcache, 'id=%',[tmpid]);
try
tmpid := Rec.ID;
cur64 := Rec.Time;
finally
Rec.Free;
end;
end;it s ugly,but it works.
any good idea?
how to delete many rows of TSQLRest with where condition?
thanks.
pls show an example about how to send/get binary data to/from server using an interface-based service.
thanks.
many thanks.
Would you change the code of function "TSQLRestClientURI.CallBackPut" in SQLite3Commons.pas:
from:
...
result := URI(Model.getURICallBack(aMethodName,aTable,aID),
'PUT',nil,aResponseHead,@aSentData).Lo;
...
to:
...
result := URI(Model.getURICallBack(aMethodName,aTable,aID),
'PUT',@aResponse,aResponseHead,@aSentData).Lo;
...
so as i can get aParams.Resp when i use CallBackPut.
thanks,i got it.
when TSQLite3HttpClient(Client).CallBackGetResult was called,httpserver got the aParams value using "GET" methord with "url",
is it able to use post instead of get methord,so httpserver gets the aParams value using "POST" methord with "incontent"?
sometimes the length limit is a problem.
thanks,
What i exactly want to do is:
load/save binary data(TMemoryStream,not only Tsynpicture) from/into database.
i used bintohex and hextobin to convert between binary and RawUTF8, and then load/save RawUTF8 from/into database,
sometimes i want to use TSQLRawBlob instead of RawUTF8...
i know how to use bintohex,but can not use hextobin to convert RawUTF8 to TSQLRawBlob.
any one any help?
thanks.
i just add a timer1 to the Project04Client of "04 - HTTP Client-Server" and the following script:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
FindButton.Click;
end;
excise is ok,samples9 , sample6 and sample4 are all built into one, and the server side uses just one ip address and one port.
but the memory keeps increasing...
for samples4,add a timer event with the following script:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
FindButton.Click;
end;
add a big text record and then fire the Timer1,the Project04Server.exe memory keeps increasing...
thanks again, and i will finish it soon.
thanks.
sample04 and sample06 are all fine.
i hope sample6 with HTTP but no named pipe,not just sample4.
it is better if samples9 , sample6 and sample4 are all built into one, and the server side uses just one ip address and one port.
how to implement it using HTTP ,without named pipe?
sorry for my poor english.
i compiled project04 and it run successful.
i run project04server.exe on my computer and a remote computer respectively,with "add the message",project04client.exe connected to the remote server run little faster. on the other hand,with "find a previous message",project04client.exe connected to my computer server run much faster.
how does the network affect the effect?
many many thanks,ab
update the source code,two problems are still remained:
1. the text position is not exactly right, all arranged on the upper left corner.
2. many more text does appear, but a few part of content is still not appeared.