1 |
mlimic |
535 |
<?php |
2 |
|
|
|
3 |
|
|
|
4 |
|
|
class CurlSendREST { |
5 |
|
|
|
6 |
|
|
|
7 |
|
|
public function __construct() { |
8 |
|
|
// |
9 |
|
|
} |
10 |
|
|
|
11 |
|
|
public function __destruct() { |
12 |
|
|
// |
13 |
|
|
} |
14 |
|
|
|
15 |
|
|
public function curlPost($url, $data) { |
16 |
|
|
$ret = 'OK'; |
17 |
|
|
$data_string = json_encode($data); |
18 |
|
|
|
19 |
|
|
$ch = curl_init($url); |
20 |
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
21 |
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); |
22 |
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
23 |
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
24 |
|
|
'Content-Type: application/json', |
25 |
|
|
'Content-Length: ' . strlen($data_string)) |
26 |
|
|
); |
27 |
|
|
$result = curl_exec($ch); |
28 |
|
|
if ($result === false) { |
29 |
|
|
$ret = curl_error($ch); |
30 |
|
|
} |
31 |
|
|
curl_close($ch); |
32 |
|
|
return $ret; |
33 |
|
|
} |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
?> |