How can I access the raw HTTP request data with PHP/apache?

后端 未结 3 1670
感情败类
感情败类 2021-02-19 00:53

I was wondering if there was a way to get at the raw HTTP request data in PHP running on apache that doesn\'t involve using any additional extensions. I\'ve seen the HTTP functi

相关标签:
3条回答
  • 2021-02-19 01:32

    Use the following php wrapper:

    $raw_post = file_get_contents("php://input"); 
    
    0 讨论(0)
  • 2021-02-19 01:37

    Try this:

      $request = $_SERVER['SERVER_PROTOCOL'] .' '. $_SERVER['REQUEST_METHOD'] .' '. $_SERVER['REQUEST_URI'] . PHP_EOL;
    
      foreach (getallheaders() as $key => $value) {
        $request .= trim($key) .': '. trim($value) . PHP_EOL;
      }
    
      $request .= PHP_EOL . file_get_contents('php://input');
    
      echo $request;
    
    0 讨论(0)
  • 2021-02-19 01:45

    Do you mean the information contained in $_SERVER?

    print_r($_SERVER);
    

    Edit:

    Would this do then?

    foreach(getallheaders() as $key=>$value)  {
        print $key.': '.$value."<br />";
    }
    
    0 讨论(0)
提交回复
热议问题