Webservice, webhook, socket test

  1. <?php
  2. class DumpHTTPRequestToFile {
  3. public function execute($targetFile) {
  4. $data = sprintf(
  5. "%s %s %s\n\nHTTP headers:\n",
  6. $_SERVER['REQUEST_METHOD'],
  7. $_SERVER['REQUEST_URI'],
  8. $_SERVER['SERVER_PROTOCOL']
  9. );
  10. foreach ($this->getHeaderList() as $name => $value) {
  11. $data .= $name . ': ' . $value . "\n";
  12. }
  13. $data .= "\nRequest body:\n";
  14. $targetFile,
  15. $data . file_get_contents('php://input') . "\n"
  16. );
  17. echo("Done!\n\n");
  18. }
  19. private function getHeaderList() {
  20. $headerList = [];
  21. foreach ($_SERVER as $name => $value) {
  22. if (preg_match('/^HTTP_/',$name)) {
  23. // convert HTTP_HEADER_NAME to Header-Name
  24. $name = strtr(substr($name,5),'_',' ');
  25. $name = ucwords(strtolower($name));
  26. $name = strtr($name,' ','-');
  27. // add to list
  28. $headerList[$name] = $value;
  29. }
  30. }
  31. return $headerList;
  32. }
  33. }
  34. (new DumpHTTPRequestToFile)->execute('./dumprequest.txt');

Leave a Reply

You must be logged in to post a comment.