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

后端 未结 3 1680
感情败类
感情败类 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: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;
    

提交回复
热议问题