1 |
<?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 |
$data_string = json_encode($data); |
17 |
|
18 |
$ch = curl_init($url); |
19 |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
20 |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); |
21 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
22 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
23 |
'Content-Type: application/json', |
24 |
'Content-Length: ' . strlen($data_string)) |
25 |
); |
26 |
$ret = curl_exec($ch); |
27 |
if ($ret === false) { |
28 |
$ret = "\"curlerror\" : ".curl_error($ch); |
29 |
} |
30 |
curl_close($ch); |
31 |
return $ret; |
32 |
} |
33 |
} |
34 |
|
35 |
?> |