Advertisement
kura2yamato

hit 1 dan 2

Sep 29th, 2021
1,260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  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. $url1= "http://172.16.0.188:1688/sim_status";
  6. $ch_site1 = curl_init($url);
  7. $param_get=array(
  8.     'username'=>'CAN****',
  9.     'to'=>'08****'
  10. );
  11. curl_setopt($ch_site1, CURLOPT_POST, 0); // karena get
  12. curl_setopt($ch_site1, CURLOPT_TIMEOUT, 20); //timeout 20
  13. curl_setopt($ch_site1, CURLOPT_POSTFIELDS, http_build_query( $param_get ) );
  14. curl_setopt($ch_site1, CURLOPT_RETURNTRANSFER, 1);
  15. //harus pastikan apakah bisa nerima json.. ato array
  16. //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  17.  
  18. $result = curl_exec($ch_site1);
  19. $data  = json_decode($result, 1);
  20. //$output = curl_exec($ch);
  21. curl_close($ch_site1);
  22.  
  23. /* asumsikan datanya jadi dibawah */
  24.  
  25. ///url yg mau dikirim datanya isi dari url1 ke url2
  26. $url = 'http://172.16.0.4:81818/reportku/gaspol/data';
  27. //asumsikan ini adalah array hasil dari url 1
  28. $data = array(
  29.     "first_name" => "First name",
  30.     "last_name" => "last name",
  31.     "email"=>"email@gmail.com",
  32.     "addresses" => array (
  33.         "address1" => "some address" ,
  34.         "city" => "city",
  35.         "country" => "CA",
  36.         "first_name" =>  "Mother",
  37.         "last_name" =>  "Lastnameson",
  38.         "phone" => "555-1212",
  39.         "province" => "ON",
  40.         "zip" => "123 ABC"
  41.     )
  42. );
  43.  
  44.  
  45. //ngak berhasil
  46. //$postdata = json_encode($data);
  47. $ch = curl_init($url);
  48.  
  49. curl_setopt($ch, CURLOPT_POST, 1);
  50. curl_setopt($ch, CURLOPT_TIMEOUT, 20); //timeout 20
  51. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query( $data ) );
  52. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  53. //harus pastikan apakah bisa nerima json.. ato array
  54. //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  55.  
  56. $result = curl_exec($ch);
  57. $output = json_decode($result, 1);
  58. //$output = curl_exec($ch);
  59. curl_close($ch);
  60. if(is_array($ouput))
  61. {
  62.     echo '<pre>'.print_r($output,1).'</pre>';
  63. }
  64. else
  65. {
  66.     echo $result;
  67. }
  68.  
  69.  
  70. //echo json_encode($ch);
  71. //echo json_encode($data);
  72. //echo $output;
  73.  
  74.  
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement