You are not logged in.
Hi I'm new at mormot, and started to create a server based on sample: "09 - HttpApi web server"...
What I tring to do: Delphi xe7 http server with oracle database, for json e and file transfer. And and Firemonkey client for android.
So far i manage the server with oracle, a json client for android (using TRestclient on firemonkey) and it works very nice....
But i can't manage to download pdf files with TRestClient or IndyHttp (with webrowsers works).
When trying to download via mormot server i get: "Project WebBrowser.exe raised exception class EIdHTTPProtocolException With Message 'HTTP/1.1 0 0'."
But the same file with the same client in a ftp works...
My server:
Ctxt.OutCustomHeaders := HEADER_CONTENT_TYPE + HTTP_RESP_STATICFILE + #13#10 + HEADER_CONTENT_TYPE + GetMimeContentType(ctxt, 200, filename);
Ctxt.OutContentType := HTTP_RESP_STATICFILE;
Ctxt.OutContent := ExtractFilePath(filename) + ExtractFileName(filename);
idHttp configuration:
object IdHTTP1: TIdHTTP
AllowCookies = True
ProxyParams.BasicAuthentication = False
ProxyParams.ProxyPort = 0
Request.ContentLength = -1
Request.ContentRangeEnd = -1
Request.ContentRangeStart = -1
Request.ContentRangeInstanceLength = -1
Request.Accept =
'STATICFILE, !STATICFILE, application/pdf,text/html,application/x' +
'html+xml,application/xml;q=0.9,*/*;q=0.8'
Request.BasicAuthentication = False
Request.UserAgent =
#39'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Fir' +
'efox/12.0'
Request.Ranges.Units = 'bytes'
Request.Ranges = <>
HTTPOptions = [hoKeepOrigProtocol, hoWaitForUnexpectedData]
OnAuthorization = IdHTTP1Authorization
end
Idhttp call:
MyFile := TFileStream.Create(sCaminhoPastaLocal + prNomeRel, fmCreate);
try
IdHTTP1.Request.CacheControl:= 'no-cache';
IdHTTP1.OnWork:= NIL;
IdHTTP1.OnWorkBegin:= NIL;
IdHTTP1.OnWorkEnd:= NIL;
IdHTTP1.Get(sCaminhoPdf,myFile);
finally
MyFile.Free;
end;
Offline
On the Server side, you may use Ctxt.ReturnFile() directly.
On the Client/Indy side, IMHO you has nothing to add in respect to a standard HTTP GET request.
There is actually NO need of STATICFILE !STATICFILE on client side: those STATICFILE headers are pseudo-headers, only appearing on the server side, and which will be removed from the actual HTTP headers sent to the client.
Offline
On the Server side, you may use Ctxt.ReturnFile() directly.
I do not have this function on my ctxt...
function TTestServer.Process(Ctxt: THttpServerRequest): cardinal;
Offline
Still dont find it...
I just download it from:
http://synopse.info/files/mORMotNightlyBuild.zip
and also check it in:
https://github.com/synopse/mORMot/blob/ … rtSock.pas
Offline
I find the function 'Ctxt.ReturnFile()' on ORMserver (from RestFull example...)
So i mixed both httpApiServer and and ormServer into one...
I really dont know if it's the best way to do it, but works
var
fServer: TSQLHttpServer;
ORMServer: TNoteServer;
HTTPServer: THttpApiServer;
...
HTTPServer := THttpApiServer.Create(false);
HTTPServer.AddUrl('root','889',false,'+',true);
HTTPServer.RegisterCompress(CompressDeflate);
HTTPServer.OnRequest := process;
ORMServer := TNoteServer.Create(ExeVersion.ProgramFilePath+'data','root');
fServer := TSQLHttpServer.Create(HTTP_PORT,[ORMSERVER]);
Offline
Both those files do have the method!
The mORMotNightlyBuild have it, but not for httpApiServer.....
In the SynCrtSock.pas, i do not find it at all...
Offline
Do not use SynCrtSock, but a method-based service, if you can.
See http://synopse.info/files/html/Synopse% … ml#TITL_95
Using plain httpApiServer won' t be faster, and less convenient.
If you use a TSQLRestServerFullMemory, it would add very little dependencies, and a lot of features, even for HTTP (cookies, Ctxt.ReturnFile).
Offline
I'm doing your sugestion, and changing to TSQLRestServerFullMemory
So far it's working
Thank you!
Offline