]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - test-api.php
Initial commit (importing from http://svn.planetozh.com/ozhin)
[Github/YOURLS.git] / test-api.php
1 <?php\r
2 \r
3 // POST parameters\r
4 $post_data = array( 'url' => 'http://planetozh.com/', 'keyword'=>'ozh', 'format'=>'json' );\r
5 \r
6 // Init the CURL session\r
7 $ch = curl_init();\r
8 curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1/ozh.in/api.php");       // URL of the API file\r
9 curl_setopt($ch, CURLOPT_HEADER, 0);                                                            // No header in the result\r
10 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);                                       // AUTH with any (best) method available\r
11 curl_setopt($ch, CURLOPT_USERPWD, 'ozh:richward');                                      // login/pwd as defined in config.php\r
12 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                         // Return, do not echo result\r
13 curl_setopt($ch, CURLOPT_POST, 1);                                                                      // This is a POST request\r
14 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);                                       // Data to POST\r
15 \r
16 // Grab URL and return content\r
17 $data = curl_exec($ch);\r
18 curl_close($ch);\r
19 \r
20 // Echo result (either a new short URL, or an error message beginning with "Error")\r
21 echo htmlentities($data);\r
22 \r
23 ?>