ph_posturl1 PowerHome formula function
Description
Use this function to retrieve HTML from the specified URL using an HTTP POST command (vs the GET command that is used in the ph_geturl functions). This allows you to pass large amounts of data (such as form data) to the specified URL
Syntax
ph_posturl1 ( as_url, as_postdata, ai_type, al_timeout )
ph_posturl1 ( as_url, as_headers, as_postdata, ai_type, al_timeout )
Argument |
Description |
as_url |
String. The URL whose HTML you wish to retrieve |
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_postdata |
String
. The data and parameters you would like
to "POST" to the specified URL via HTTP. This data is passed in the body of the request. If you have no data to post, use an empty string "" |
ai_type |
Integer. A number representing the internal 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.
The raw HTML returned from the requested
URL. Various errors may be encountered depending upon the internal 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
Most of the time, the ph_geturl or ph_geturl1 function is all that is needed in order to retrieve raw HTML from a
website. This is accomplished via an HTTP GET command. Some websites though, for
whatever reason, don't support an HTTP GET and instead require an HTTP POST.
This function allows you to retrieve data from these websites. A very good
explanation of the differences between POST and GET can be found here:
http://www.w3schools.com/tags/ref_httpmethods.asp
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_posturl function). The HTTP POST 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 |
Retrieves the
HTML using a PowerBuilder internal HTTP control. Unlike the equivalent internal method in
ph_geturl1,
this type does support the use of
additional headers. The al_timeout parameter is in seconds |
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 |
Not Supported. Returns an error message |
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 |
Not Supported. Returns an error message |
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_posturl1("https://mobile.weather.gov/index.php","lat=28.6867&lon=-81.5133&unit=0&lg=english",5,5000)
The above example will retrieve the raw HTML for the
mobile.weather.gov website via an "msxml2.xmlhttp" control using an
HTTP POST command. The function will timeout in 5 seconds (5000 milliseconds) if
the result hasnt been returned by
then.