Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //url 1 yg mau diambil datanya
- $BASE_URL = "http://172.16.0.188:1688/sim_status?username=CAN3269095&to=082169000123";
- ///url yg mau dikirim datanya isi dari url1 ke url2
- $url = 'http://172.16.0.4:81818/reportku/gaspol/data';
- //asumsikan ini adalah array hasil dari url 1
- $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"
- )
- );
- header("Refresh: 5");
- //ngak berhasil
- //$postdata = json_encode($data);
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 20); //timeout 20
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query( $data ) );
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- //harus pastikan apakah bisa nerima json.. ato array
- //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
- $result = curl_exec($ch);
- $output = json_decode($result, 1);
- //$output = curl_exec($ch);
- curl_close($ch);
- if(is_array($ouput))
- {
- echo '<pre>'.print_r($output,1).'</pre>';
- }
- else
- {
- echo $result;
- }
- //echo json_encode($ch);
- //echo json_encode($data);
- //echo $output;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement