Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function curl($url, $method = 'GET', $data = [], $timeout = 300) {
- $c = curl_init();
- curl_setopt($c, CURLOPT_URL, $url);
- curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($c, CURLOPT_FAILONERROR, true);
- curl_setopt($c, CURLOPT_CONNECTTIMEOUT, $timeout);
- curl_setopt($c, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($c, CURLOPT_HTTPHEADER, array(
- 'Accept: application/json',
- 'Content-Type: application/json'
- ));
- if ($method == 'POST') {
- curl_setopt($c, CURLOPT_POST, true);
- curl_setopt($c, CURLOPT_POSTFIELDS, $data);
- }
- $content = (string) curl_exec($c);
- $http_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
- $curl_error = curl_error($c);
- curl_close($c);
- return $content;
- }
- $url = 'http://localhost/destination';
- $data = [
- 'nik' => '123',
- 'user_id' => 'user',
- 'password' => 'xxxxxx',
- 'ip_user' => '127.0.0.1'
- ];
- // Merubah menjadi json
- $data = json_encode($data);
- $response = curl($url, 'POST', $data);
- var_dump($response);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement