如何在 PHP 中获取请求内容(正文)?

2022-01-05 00:00:00 request php

我正在向内容中包含 XML 的 php 服务器发送请求:

I am sending a request to a php server with a XML in the content:

POST /index3.php HTTP/1.0
Connection: Close
Accept: application/xml
Content-Type: text/xml

<?xml version="1.0" encoding="UTF-8"?>
<root />

我已经检查了全局变量(例如 $_GET$_POST$_ENV$_FILES>, $_REQUEST...) 但它们都是空的.

I've checked in globals vars (like $_GET, $_POST, $_ENV, $_FILES, $_REQUEST...) but they are all empty.

如何检索服务器中的内容?

How could I retrieve the content in the server?

推荐答案

试试这个

$xml = file_get_contents('php://input');

来自手册:

php://input 是一个只读流,允许您从请求正文中读取原始数据.

php://input is a read-only stream that allows you to read raw data from the request body.

相关文章