-
Notifications
You must be signed in to change notification settings - Fork 0
/
hc_curl.php
40 lines (34 loc) · 1.04 KB
/
hc_curl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/**
* Created by PhpStorm.
* User: vallefor
* Date: 02.08.14
* Time: 20:21
*/
require_once $_SERVER["DOCUMENT_ROOT"]."/config.php";
function execCurl($urlAdd,$method='GET',$data=false)
{
//http://<HC2 ip address>/api/sceneControl?id=14&action=start
$URL='http://192.168.1.138/api/'.$urlAdd;
$username=HC2_LOGIN;
$password=HC2_PASS;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_HEADER, false);
if($method=='PUT')
curl_setopt($ch, CURLOPT_PUT, true);
if($data)
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
$result=curl_exec($ch);
curl_close($ch);
return $result;
//echo $status_code.":".$result;
}
?>