Recent

Author Topic: timelimit for HTTPMethod  (Read 442 times)

DeroB73

  • New member
  • *
  • Posts: 6
timelimit for HTTPMethod
« on: December 07, 2019, 09:15:21 pm »
Hello
is it possible to set a time limit for the Synapse HTTPMethod GET method ?
I am trying a huge list from URLs to see i they are still alive.
TTPMethod('GET','http://123.123.123/index.') works  great as long status is 200 but for dead links 400 it takes 2 a 3 seconds that's to long.
 
Greets 

fjabouley

  • Full Member
  • ***
  • Posts: 103
Re: timelimit for HTTPMethod
« Reply #1 on: December 07, 2019, 09:33:18 pm »

Try to add HTTP.Sock.ConnectionTimeout




Code: Pascal  [Select][+][-]
  1. Function Getwithtimeout(URL:string;Default_timeout:integer=1000):string;
  2. var response : Tstringlist;
  3. var HTTP : THTTPSend;
  4. begin
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.   Result := '';
  12.   Response := TStringList.Create;  
  13.  
  14.  
  15.   HTTP := THTTPSend.Create;
  16.   HTTP.Timeout := Default_timeout;
  17.   HTTP.Sock.ConnectionTimeout := Default_timeout;
  18.   if HTTP.HTTPMethod('GET', URL) then
  19.   begin
  20.     if HTTP.ResultCode <> 200 then
  21.     begin
  22.     // Error : do some stuff
  23.     end
  24.     else
  25.     begin
  26.       Response.LoadFromStream(HTTP.Document);
  27.       Result := response.Text;
  28.     end;
  29.  
  30.  
  31.  
  32.  
  33.   end;
  34.   Response.Free;
  35.   HTTP.Free;
  36. end;
  37.  




or




Code: Pascal  [Select][+][-]
  1. Function IsCorrectURL(URL:string;Default_timeout:integer=1000):boolean;
  2. var response : Tstringlist;
  3. var HTTP : THTTPSend;
  4. begin  
  5. Result := false;
  6. HTTP := THTTPSend.Create;
  7. HTTP.Timeout := Default_timeout;
  8. HTTP.Sock.ConnectionTimeout := Default_timeout;
  9. if HTTP.HTTPMethod('GET', URL) then if HTTP.ResultCode = 200 then Result:=true;
  10. HTTP.Free;
  11. end;
  12.  

« Last Edit: December 07, 2019, 09:41:56 pm by fjabouley »

DeroB73

  • New member
  • *
  • Posts: 6
Re: timelimit for HTTPMethod
« Reply #2 on: December 08, 2019, 12:47:52 pm »
thanks fjabouley

it seems i have learn Synapse more in dept.

 

TinyPortal © 2005-2018