Forum > Networking and Web Programming
Http Server
michoux:
Hello
I created a new HTTP Server Application in Lazarus on port 8080
When ever I try to reach it on localhost:8080 from browser I get following erro
************************************++
The application encountered the following error:
Error: Not found
Stack trace:
$00438D3C
$0043873C
$00438D9E
$0043234F
$00432A47
$0042BCA5
$00436047
$004359FF
$00435B84
$004219F1
$00402B7F
$7730FEF9
$778C7BBE
$778C7B8E
*******************************
michoux:
Somehow now server is working :)
I have following code, it is from tutorial of fpweb
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure JSON(req: TRequest; res: TResponse);var n: Integer; f: TUploadedFile; i: Integer;begin n := req.Files.Count; if n = 0 then with res.Contents do begin Add('<form id="form" action="' + req.URI + '" method="POST" enctype="multipart/form-data">'); Add('<label for="name">Drag n drop or click to add file:</label>'); Add('<input type="file" name="input" />'); Add('<input type="submit" value="Send" />'); Add('</form>'); end else begin f := req.Files[0]; res.Contents.LoadFromStream(f.Stream); end; end;
I want to change this so that I receive file directly with post
For example with curl.
c:\curl\bin\curl.exe -X GET --data-binary @c:\test.xml http://localhost:9080
Regards Mich
michoux:
Hi,
Ok I found out all is written in request.
just a simple code will output the file content posted with curl.
c:\curl\bin\curl.exe -X GET --data-binary @c:\live_timing\race.xml http://localhost:9080/
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure JSON(req: TRequest; res: TResponse);var n: Integer; f: TUploadedFile; i: Integer; s:string;begin s := req.Content; writeln(s); end;
michoux:
Now I have next question.
I make a form and I start a web server with a button.
form1.FPHttpServer2.Active:=true
This blocks my app totally.
PierceNg:
--- Quote from: michoux on December 05, 2022, 01:15:46 pm ---Now I have next question.
I make a form and I start a web server with a button.
form1.FPHttpServer2.Active:=true
This blocks my app totally.
--- End quote ---
Run the HTTP server on a thread. Something like this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type TWebServerThread = class(TThread) protected procedure Execute; override; public constructor Create(CreateSuspended: boolean); end; constructor TWebServerThread.Create(CreateSuspended: boolean);begin inherited Create(CreateSuspended); FreeOnTerminate := true;end; procedure TWebServerThread.Execute;begin fphttpapp.Application.Run;end;
Navigation
[0] Message Index
[#] Next page