HttpWebRequest.php 931 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. // Dump it...
  3. @file_put_contents('GET.txt', print_r($_GET, true));
  4. // Data POSTed is JSON.
  5. if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'application/json')
  6. {
  7. if (!($input = @file_get_contents("php://input")) || ($json = @json_decode(@utf8_encode($input))) === null)
  8. {
  9. echo json_encode(array('Error' => 'No input given', 'SentHeaders' => getallheaders()));
  10. exit;
  11. }
  12. // Dump it...
  13. @file_put_contents('POST.json', $input);
  14. // Do stuff with the POSTed JSON (read from HttpWebRequest->Data).
  15. //$json->glossary->title = "nsJSON NSIS plug-in";
  16. }
  17. // Data POSTed as key value pairs.
  18. else
  19. {
  20. // Dump it...
  21. @file_put_contents('POST.txt', print_r($_POST, true));
  22. //$myValue = $_POST['MyValue'];
  23. }
  24. // Now respond with JSON (downloaded into HttpWebResponse).
  25. echo json_encode(array('FirstName' => 'Stuart', 'LastName' => 'Welch', 'NickName' => 'Afrow UK', 'Email' => 'afrowuk@afrowsoft.co.uk'));
  26. ?>