1// API URL
2$url = 'http://www.example.com/api';
3
4// Create a new cURL resource
5$ch = curl_init($url);
6
7// Setup request to send json via POST
8$data = array(
9 'username' => 'codexworld',
10 'password' => '123456');
11$payload = json_encode(array("user" => $data));
12
13// Attach encoded JSON string to the POST fields
14curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
15
16// Set the content type to application/json
17curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
18
19// Return response instead of outputting
20curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
21
22// Execute the POST request
23$result = curl_exec($ch);
24
25// Close cURL resource
26curl_close($ch);
1<?php
2$jsonurl = "http://api.wipmania.com/json";
3$json = file_get_contents($jsonurl);
4var_dump(json_decode($json));
5?>