Advertisement
kura2yamato

cek this

Sep 29th, 2021
1,408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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(
  9.     "first_name" => "First name",
  10.     "last_name" => "last name",
  11.     "email"=>"email@gmail.com",
  12.     "addresses" => array (
  13.         "address1" => "some address" ,
  14.         "city" => "city",
  15.         "country" => "CA",
  16.         "first_name" =>  "Mother",
  17.         "last_name" =>  "Lastnameson",
  18.         "phone" => "555-1212",
  19.         "province" => "ON",
  20.         "zip" => "123 ABC"
  21.     )
  22. );
  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. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement