Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCPServer send html to browser

Tags:

sockets

delphi

I am working on a project in which I must implement a simple web server just to display a welcome page. So I placed a TTCPServer on my form and I can successfully send a plain text to a browser that interacts with the server. But how can I send HTML ?

I tried this but doesn't work.

ClientSocket.Sendln('HTTP/1.0 200 OK');
ClientSocket.Sendln('MIME-version: 1.0');
ClientSocket.Sendln('Content-type: text/html');
ClientSocket.Sendln('Content-Length:'+IntToStr(Length(webpage)+10));
ClientSocket.Sendln(AnsiString(Format(webpage, [va, ma, mi, timexx])));

Any ideas ? I don't want to use another component anyway.

like image 742
opc0de Avatar asked Oct 12 '11 13:10

opc0de


1 Answers

You need an additional CRLF after the last header so the browser can determine end-of-headers and start-of-body.

like image 93
Alex K. Avatar answered Sep 18 '22 17:09

Alex K.