Advertisement
Guest User

Curl New

a guest
Nov 20th, 2019
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <?php
  2. $url = 'https://webservice.jogjakota.go.id/ws_pbb/index.php/univ-inquiry';
  3.  
  4. $requestHeader = [
  5. 'Content-Type' => 'application/x-www-form-urlencoded',
  6. ];
  7.  
  8. $requestBody = [
  9. 'token' => "22c56057e3e970a41c7027d6596ea5c8",
  10. 'nop' => "347101000100100130",
  11. 'tahun' => "2014",
  12. 'kdbank' => "10122601"
  13.  
  14. ];
  15.  
  16. $responseJson = CurlHelper::post($url, $requestHeader, $requestBody);
  17. $response = json_decode($responseJson, true);
  18.  
  19.  
  20. public static function post_json_proxy($url, $param, $getmessage=null){
  21. try {
  22. $ch = curl_init();
  23. curl_setopt($ch, CURLOPT_URL, $url);
  24. curl_setopt($ch, CURLINFO_HEADER_OUT, true);
  25. curl_setopt($ch, CURLOPT_POST, true);
  26.  
  27. if ($getmessage !=null){
  28. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Authorization:Bearer ' .$getmessage ));
  29.  
  30. }else{
  31. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  32.  
  33. }
  34. curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
  35. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  36. $rs = curl_exec($ch);
  37. curl_close($ch);
  38.  
  39. } catch (Exception $ex) {
  40. $rs = $ex->getMessage();
  41. }
  42. return $rs;
  43.  
  44. }
  45.  
  46. $responseJson = self::post_json_proxy($url, $requestHeader, $requestBody);
  47.  
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement