如何在PHP中获取请求内容(正文)? [英] How to get request content (body) in PHP?

查看:249
本文介绍了如何在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.

这篇关于如何在PHP中获取请求内容(正文)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆