deependrsingh

CURL BLockchain

Jul 17th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1.  <?php
  2.     if(isset($_POST['mysubmit'])){
  3.         $data = $_POST['data'];
  4.        
  5.         $address = $_POST['address'];
  6.        $url='http://192.168.43.70:8374/';
  7.         $data = bin2hex($data);
  8.         echo $data;
  9.        
  10.                
  11.         $payload=json_encode(array(
  12.             'id' => 'rpc',
  13.             'method' => 'sendwithdata',
  14.             'params' =>[$address, 0, $data],
  15.         ));
  16.        
  17.        
  18.     //  echo '<PRE>'; print_r($payload); echo '</PRE>';
  19.         $user = 'digichain';
  20.         $password = "password";
  21.         $ch=curl_init($url);
  22.         curl_setopt($ch, CURLOPT_POST, true);
  23.         curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
  24.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  25.         curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$password);
  26.         curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  27.             'Content-Type: application/json',
  28.             'Content-Length: '.strlen($payload)
  29.         ));
  30.        
  31.         $response=curl_exec($ch);
  32.        
  33.     //  echo '<PRE>'; print_r($response); echo '</PRE>';
  34.        
  35.         $result=json_decode($response, true);
  36.        
  37.         $final_result = $result['result'];
  38.     }
  39.     ?>
Add Comment
Please, Sign In to add comment