Forum > Networking and Web Programming

TFPHttpClient timeout error

(1/3) > >>

jhorta:
Im trying to connect and post to an api running on my local machine using TFPHttpClient but im getting a timeout error. Everything Works fine when i call via Postman.

I tried to use the ConnectTimeout property(60) but I kept getting the same error.

Any tips? Could I be missing something?

Running on Windows 10, Lazarus 3.4

Error : Connection to localhost:4000 timed out.

My code:


--- 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 Send;Var Client: TFPHttpClient;    Response: TStringStream;Begin   Client := TFPHttpClient.Create(nil);   Client.AddHeader('Content-Type', 'application/json; charset=UTF-8');   Client.RequestBody := TRawByteStringStream.Create('{"jwt": "", ' + '"codAplicacao": "F60EB930-9B1B-11EF-9657-02240D86274B"}');    Response := TStringStream.Create('');    Try      Try         Client.Post('http://localhost:4000/local/inicio/hortech', Response);         GeraLog('Response: ' + String(Response));       Except on E: Exception do          Begin             GeraLog('Something wrong: ' + E.Message);          End;       End;   Finally       Client.RequestBody.Free;       Client.Free;       Response.Free;   End;End; 

jhorta:
I tried a few things but nothing worked. A bit frustrating. I should add that during some testing, I noticed that the error message occurs for any url, even if it doesn't exist or is unavailable. I appreciate any tips, links, etc.

paweld:
The error may be due to the fact that the program is blocked on the firewall.
Overall the code is almost OK, only you have an error when get the response string - it should be:
--- 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";}};} ---GeraLog('Response: ' + Response.DataString);instead of:

--- 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";}};} ---GeraLog('Response: ' + String(Response));

Thaddy:
ConnectTimeout property, I believe 60 are ms, so make it much higher, like 1000. A timeout of 60ms is useless.

jhorta:
ConnectTimeout set to 1000, 2000, 3000...

permission for the program configured in the firewall

Firewall disabled

Nothing worked

Navigation

[0] Message Index

[#] Next page

Go to full version