MORMOT is a free open source SDK, which encapsulates HTTP.SYS, this is the reason many people use it, it was hard to imagine that it actually supports DELPHI6 and above.
Copy the following files MORMOT the unit:
SynCommons.pas, SynCrtSock.pas, SynLZ.pas, SynZip.pas, SynCrtSock.pas,
Synopse.inc,SynopseCommit.inc,
trees.obj,deflate.obj。
A total of only nine files.
1 unit Unit1; 2 3 interface 4 5 uses 6 SynCommons, SynCrtSock, SynZip, Winapi.Windows, Winapi.Messages, 7 System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, 8 Vcl.Forms, Vcl.Dialogs; 9 10 type 11 TfrmMain = class(TForm) 12 procedure FormCreate(Sender: TObject); 13 procedure FormDestroy(Sender: TObject); 14 private 15 { Private declarations } 16 SVR: THttpApiServer; . 17 // / <Summary> 18 is // / http client processing requests, and returns the result . 19 // / </ Summary> 20 is // / <param name = "ctxt"> http request </ param> 21 is // / <Returns> --200 success; failure --404 </ Returns> 22 is function Process (ctxt: THttpServerRequest): Cardinal; 23 is public 24 { public Declarations } 25 End ; 26 is 27 var 28 the frmMain: TfrmMain; 29 30 Implementation 31 is 32 { $ R & lt *. Dfm } 33 is 34 is { TForm1 } 35 36 Procedure TfrmMain.FormCreate (Sender: TObject); 37 [ the begin 38 is SVR:. = THttpApiServer the Create (True); // Create a communication http 39 svr.RegisterCompress (CompressGZip); // compression 40 svr.Clone ( 8 ); // create N worker threads 41 svr.AddUrl ( '' , ' 81 ' , False, ' + ' , True); // Register the URL of HTTP 42 svr.AddUrl ( '', ' 91 is ' , True, ' + ' , True); // registered URL HTTPS 43 is svr.OnRequest: = Process; // process communication event 44 is svr.Start; // open HTTP communication 45 End ; 46 is 47 Procedure TfrmMain. FormDestroy (Sender: TObject); 48 the begin 49 svr.Shutdown; 50 svr.Free; 51 is End ; 52 is 53 is function TfrmMain.Process (ctxt: THttpServerRequest): Cardinal; 54 is var 55 Method:String ; 56 is Fn: RawUTF8; 57 is the begin 58 the Result: = 404 ; // failure --404; success --200 59 Ctxt.OutCustomHeaders: = ' Access-Control-the Allow-Origin: * ' ; // allow cross-domain access 60 Ctxt.OutContentType: = ' text / Plain; charset = GBK ' ; // answer style and character set 61 is Method: = Ctxt.method; 62 is IF Method = ' the GET ' the then 63 is the begin 64 fn := SynCommons.StringReplaceChars(UrlDecode(copy(Ctxt.URL, 2, MaxInt)), '/', '\'); 65 end 66 else if method = 'POST' then 67 begin 68 69 end; 70 end; 71 72 end.