/[openfoncier]/trunk/services/curlsendrest.php
ViewVC logotype

Annotation of /trunk/services/curlsendrest.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 535 - (hide annotations)
Wed Oct 24 16:41:32 2012 UTC (12 years, 3 months ago) by mlimic
File size: 1431 byte(s)
saving the file that sends a POST via curl to an external service
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     ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26