ph_httprequest PowerHome formula function
Description
Makes an HTTP request to a server and returns the result. This function is very similar to the ph_geturl1 function but allows more detailed control 
Syntax
ph_httprequest ( as_url, as_headers, as_method, as_data, ai_type, al_timeout, ai_ignoresslcert )
Argument Description
as_url String. The URL for the HTTP Request
as_headers String. Optional HTTP headers you would like to supply with the request
as_method String. The HTTP method for the request. Some valid values are "GET", "POST", "PUT", "DELETE" and "HEAD"
as_data String. Optional data you would like to pass as part of the HTTP request
ai_type Integer . Specifies the specific control to use for making the request. Valid values are 0, 1, 2, 3, 5, 6, 7, and 9. See Usage below
al_timeout Long. The timeout for the request in milliseconds. Unlike the ph_geturl1 function, ALL valid ai_type values will use milliseconds
ai_ignoresslcert Integer. Specifies whether to ignore SSL certificate errors or not. If 0, then SSL certificate errors are NOT ignored. A value of 1 (or any other value) means SSL certificate errors are ignored. Only supported when the ai_type value is 6, 7, or 9
Return value
String. Returns the resulting HTML or other data returned by the HTTP server 
Usage
Use this function instead of the ph_geturl1 or ph_posturl1 functions when you need to ignore SSL certificate errors or need to utilize HTTP methods other than GET or POST. 

The as_headers parameter allows you to specify additional HTTP headers that are not included by default such as "Content-Type", "Cache-Control", "Pragma", etc. For any headers you wish to specify, you must have the header followed by a ":" followed by a single space followed by the header value and then terminated with either a carriage return line feed or just a line feed. So if you wish to specify a content-type and content-length header, it would look like this:

"Content-Type: application/x-www-form-urlencoded~r~nContent-Length: 2231~r~n"

The as_data parameter is where you would place the "body" of the HTTP request such as the data to be sent with a "POST" method.

The ai_type parameter specifies the specific internal control/method used to make the HTTP request. Valid values are:

  • 0 - Uses a Catalyst controls raw socket
  • 1 - Uses a Catalyst controls Hypertext Transfer Protocol control
  • 2 - Same as 1
  • 3 - Same as 1
  • 5 - Uses an MSXML2.XMLHTTP control
  • 6 - Uses an MSXML2.SERVERXMLHTTP control
  • 7 - Uses a WINHTTP.WINHTTPREQUEST control
  • 9 - Uses a C# HttpWebRequest object
  • Examples
    The following examples demonstrate typical syntax/usage for this function.
    • ph_httprequest("https://192.168.0.55/api/form1","Content-Type: application/x-www-form-urlencoded~r~n","POST","function= lights&action=on&level=128",9,5000,1)- This example specifies the Content-Type header and is using an HTTP POST method. The data to post is URLEncoded. The request is made using a C# HttpWebRequest object with a timeout of 5 seconds and ignoring SSL certificate errors.