SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | //url 1 yg mau diambil datanya | |
3 | $BASE_URL = "http://172.16.0.188:1688/sim_status?username=CAN3269095&to=082169000123"; | |
4 | ||
5 | ///url yg mau dikirim datanya isi dari url1 ke url2 | |
6 | $url = 'http://172.16.0.4:81818/reportku/gaspol/data'; | |
7 | //asumsikan ini adalah array hasil dari url 1 | |
8 | - | $data = array("first_name" => "First name","last_name" => "last name","email"=>"email@gmail.com","addresses" => array ("address1" => "some address" ,"city" => "city","country" => "CA", "first_name" => "Mother","last_name" => "Lastnameson","phone" => "555-1212", "province" => "ON", "zip" => "123 ABC" ) ); |
8 | + | $data = array( |
9 | "first_name" => "First name", | |
10 | - | $postdata = json_encode($data); |
10 | + | "last_name" => "last name", |
11 | "email"=>"email@gmail.com", | |
12 | - | curl_setopt($ch, CURLOPT_POST, 5); |
12 | + | "addresses" => array ( |
13 | - | curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); |
13 | + | "address1" => "some address" , |
14 | "city" => "city", | |
15 | - | curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); |
15 | + | "country" => "CA", |
16 | "first_name" => "Mother", | |
17 | - | $output = curl_exec($ch); |
17 | + | "last_name" => "Lastnameson", |
18 | "phone" => "555-1212", | |
19 | - | print_r ($result); |
19 | + | "province" => "ON", |
20 | "zip" => "123 ABC" | |
21 | - | echo json_encode($ch); |
21 | + | ) |
22 | - | echo json_encode($data); |
22 | + | ); |
23 | - | echo $output; |
23 | + | |
24 | header("Refresh: 5"); | |
25 | //ngak berhasil | |
26 | //$postdata = json_encode($data); | |
27 | $ch = curl_init($url); | |
28 | ||
29 | curl_setopt($ch, CURLOPT_POST, 1); | |
30 | curl_setopt($ch, CURLOPT_TIMEOUT, 20); //timeout 20 | |
31 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query( $data ) ); | |
32 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
33 | //harus pastikan apakah bisa nerima json.. ato array | |
34 | //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); | |
35 | ||
36 | $result = curl_exec($ch); | |
37 | $output = json_decode($result, 1); | |
38 | //$output = curl_exec($ch); | |
39 | curl_close($ch); | |
40 | if(is_array($ouput)) | |
41 | { | |
42 | echo '<pre>'.print_r($output,1).'</pre>'; | |
43 | } | |
44 | else | |
45 | { | |
46 | echo $result; | |
47 | } | |
48 | ||
49 | ||
50 | //echo json_encode($ch); | |
51 | //echo json_encode($data); | |
52 | //echo $output; | |
53 | ||
54 | ||
55 | ?> |