http HTTPReadString function
Return to Introduction  Previous page  Next page

function HTTPReadString(const URL: String; Timeout: Integer = 0): String;  

The HTTPReadString function provides extremely simple way to receive some data from the Web by HTTP protocol, without using acHTTP component and specifying its properties and handling the events. You just need to specify the URL (and optionally Timeout) and function will return downloaded data (or empty string, if remote host are unreachable or connection failed).  
Return value is the downloaded string, or empty string, which means that download failed for some reason.  
URLspecifies the URL of document which you wish to download;  
Timeoutoptional parameter, which specifies the time-out for downloading (in milliseconds). If a connection request takes longer than this time-out value, the request is cancele and function returns empty string (which means that download failed). Zero timeout (0) means infinite, thus the function will try to download the data without any forced interrupts.  
iiinfo Remarks
1.Don't forget to add "acHTTP" into uses clause of your unit before using this function.  
2.When you call this function, the execution of procedure from which the call are made, will suspended for some time, until the HTTP request will be complete or failed (it looks just like if you'd used acHTTP component with WaitThread property set to True).  

  Config: String;  
  Config := HTTPReadString('');  
  if Config <> '' then  
    // deal with downloaded string  
  // ANOTHER EXAMPLE: read the same config file with 10 seconds timeout  
  Config := HTTPReadString('', 10000);  
  if Config <> '' then  
    // deal with downloaded string  

See also
Timeouts and WaitThread properties of acHTTP component.  
FileReadString function from acUtils unit.