ph_saveurl1 PowerHome formula function
Description
Retrieves the resulting HTML / data from the specified URL. and saves the results to a file
Syntax
ph_saveurl1 ( as_url, as_file, ai_writemode, ai_type, al_timeout )
ph_saveurl1 ( as_url, as_headers, as_file, ai_writemode, ai_type, al_timeout )
Argument Description
as_url String. The URL whose HTML / data you wish to save to a file
as_headers String (Optional). Additional HTTP headers you would like to be sent as part of the request. Specify headers in the same format that would be used for structuring a valid HTTP request. Separate multiple headers with either a carriage return / linefeed pair or a linefeed (use the same separator for ALL the headers). An example header may look like: "Accept-Type: text/html~r~nPragma: no-cache". If this parameter is omitted, an empty string "" will be used
as_file String. The full path and filename that you wish to save the results of the URL to
ai_writemode Integer. Specifies how to save the data to the file. A value of 0 will append the data if the file already exists. Any other value will overwrite the file if it already exists
ai_type Integer. A number representing the method of HTML retrieval from the URL. See usage below for an explanation of the valid types
al_timeout Long. The max length of time in either seconds or milliseconds (dependent upon the ai_type value) to wait for the HTML return before the function times out
Return value
String. Returns either the HTTP headers from the URL request or an error message. Various errors may be encountered depending upon the method used to retrieve the HTML specified by the ai_type parameter. If an error occurs, the return value will start with "*ERROR* - " followed by a description of the error 
Usage
This function is an upgraded and expanded version of the original ph_saveurl function.

The following table details the valid values for the ai_type parameter:
0 A type of 0 will cause the HTML to be retrieved via a raw socket (this is the same as the ph_saveurl function). The HTTP request is constructed internally and then sent via a raw socket. The al_timeout parameter is in seconds
1 A type of 1 will retrieve the HTML using a Catalyst HTTP control. The al_timeout parameter is in seconds
2 A type of 2 will also retrieve the HTML using a Catalyst HTTP control but does so using slightly different methods than type 1 in case one or the other has compatibility problems. The al_timeout parameter is in seconds
3 A type of 3 will also retrieve the HTML using a Catalyst HTTP control but does so using a different method than type 1 or type 2. The al_timeout parameter is in seconds
4 Returns "*ERROR* - Not supported"
5 Retrieves the HTML using an "msxml2.xmlhttp" control. The al_timeout parameter is in milliseconds
6 Retrieves the HTML using an "msxml2.serverxmlhttp" control. The al_timeout parameter is in milliseconds
7 Retrieves the HTML using a "winhttp.winhttprequest" control. The al_timeout parameter is in milliseconds
8 Retrieves the HTML using a C# WebRequest object. The al_timeout parameter is in milliseconds
9 Retrieves the HTML using a C# HttpWebRequest object. The al_timeout parameter is in milliseconds
10 Retrieves the HTML using a C# WebClient object with the DownloadString function. The al_timeout parameter is not relevant since this method does not allow specifying a timeout
11 Returns "*ERROR* - Not supported"
12 Retrieves the HTML using a C# WebClient object with the DownloadString function. The C# WebClient object has been extended such that it supports timeout values. The al_timeout parameter is in milliseconds
13 Returns "*ERROR* - Not supported"
Any other value Any other value will result in an empty string "" being returned
Examples
The following examples demonstrate typical syntax/usage for this function.
ph_saveurl1("https://www.power-home.com/images/ph.png","c:\powerhome\ph.png",1,8,5000)
The above example will retrieve the binary data for the ph.png graphic file using a C# WebRequest object and save it to the c:\powerhome directory. The function will timeout in 5 seconds (5000 millseconds) if the result hasnt been returned by then.