I am learning how to write my first iOS application that will request some basic OIDs from the Proliphix IP Network Thermostat. Proliphix supports several methods, such as Curl; PHP and API GET and SET. Of these methods, what would be easier in Swift?
Can someone tell me how to convert one of the following methods to Swift?
Here are examples from the Proliphix API that can be found in a Google search.
Curl
Get curl -u hostname: password --data OID1.1 = http://192.168.1.100:8100/get
Set curl -u hostname: password --data OID1.10.5 = 120 --data submit = Send http://192.168.1.100:8100/pdp
GET API
URL used / get. A GET API request is a list of OIDs where their value is not specified. A correctly formatted request must contain the Content-Length header. The entry is an encoded authentication base word (see RFC 2617 -HTTP Authentication: Basic and Digest Access Authentication).
Inquiry
POST /get HTTP/1.1
Authorization: Basic <credentials>
Content-Type: application/x-www-form-urlencoded
User-Agent: Jakarta Commons-HttpClient/2.0.2
Host: 192.168.111.114:8214
Content-Length: 92
OID1.10.9=&OID1.2=&OID1.1=&OID1.4=&OID1.8=&OID2.7.1=&
Answer
HTTP/1.1 200 OK
Cache-control: no-cache
Server: Ubicom/1.1
Content-Length: 166
OID1.10.9=example@proliphix.com & OID1.2 = SW Dev 114 & OID1.1 = therm_rev_2 0.1.40 & OID1.4 = 192.168.111.114 & OID1.8 = 00: 11: 49: 00: 00: 58 & OID2.7.1 = NT100
API SET
URL-:/pdp. API API GET , , . -. (. RFC 2617 -HTTP Authentication: Basic Digest Access Authentication). "submit = Submit". '& "submit = Submit".
POST /pdp HTTP/1.1
Authorization: Basic <credentials>
Content-Type: application/x-www-form-urlencoded
User-Agent: Jakarta Commons-HttpClient/2.0.2
Host: 192.168.111.114:8214
Content-Length: 193
HTTP/1.1 200 OK
Cache-control: no-cache
Server: Ubicom/1.1
Content-Length: 308
PHP
PHP - , -, mod_perl. Apache - .
Get
$oids = array('OID1.4'=>'',
'OID1.10.5'=>'',
‘submit’=>’Submit’);
$url = "http://192.168.1.100:8100/get";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPGET, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$myHeader = array("Content-Type: application/x-www-form-urlencoded" ); curl_setopt($ch, CURLOPT_HTTPHEADER, $myHeader);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($oids)); $response = curl_exec($ch);
curl_close($ch);
$oids = array();
parse_str($response, $oids);
$localip = $oids['OID1_4'];
$interval = $oids['OID1_10_5'];