#1 2015-06-03 14:54:12

evandroxavier
Member
Registered: 2015-06-03
Posts: 6

HttpApi webServer x IndyHttp Firemonkey - PDF Files

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

#2 2015-06-03 14:57:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: HttpApi webServer x IndyHttp Firemonkey - PDF Files

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

#3 2015-06-03 15:05:14

evandroxavier
Member
Registered: 2015-06-03
Posts: 6

Re: HttpApi webServer x IndyHttp Firemonkey - PDF Files

ab wrote:

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

#4 2015-06-03 15:10:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: HttpApi webServer x IndyHttp Firemonkey - PDF Files

Ensure you use the latest 1.18 "unstable" revision, not the 1.17 "stable" version.

Offline

#5 2015-06-03 16:45:04

evandroxavier
Member
Registered: 2015-06-03
Posts: 6

Re: HttpApi webServer x IndyHttp Firemonkey - PDF Files

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

#6 2015-06-03 20:50:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: HttpApi webServer x IndyHttp Firemonkey - PDF Files

Both those files do have the method!

Offline

#7 2015-06-03 20:55:05

evandroxavier
Member
Registered: 2015-06-03
Posts: 6

Re: HttpApi webServer x IndyHttp Firemonkey - PDF Files

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 smile

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

#8 2015-06-03 21:02:03

evandroxavier
Member
Registered: 2015-06-03
Posts: 6

Re: HttpApi webServer x IndyHttp Firemonkey - PDF Files

ab wrote:

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

#9 2015-06-04 05:30:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: HttpApi webServer x IndyHttp Firemonkey - PDF Files

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

#10 2015-06-05 21:16:57

evandroxavier
Member
Registered: 2015-06-03
Posts: 6

Re: HttpApi webServer x IndyHttp Firemonkey - PDF Files

I'm doing your sugestion, and changing to TSQLRestServerFullMemory
So far it's working smile
Thank you!

Offline

Board footer

Powered by FluxBB