我正在尝试编辑和调整PHP中的其他人的REST服务器.它基于Phil Sturgeon编写的REST Server.几乎所有人都围绕着我,但我的请求没有按预期工作.
在服务器构造函数中是代码
switch ($this->request->method)
{
case 'post':
$this->_post_args = $_POST;
$this->request->format and $this->request->body =
file_get_contents('php://input');
break;
}
我知道php://输入只能读取一次,所以在设置变量之前执行var_dump(file_get_contents(‘php:// input’))表明我的XML数据正在从输入流中正确读取但显然是变量不对.
但是做var_dump($this-> request-> body)只输出NULL!是否有一种特殊的技术来存储变量中的php://输入的内容?
编辑:
我正在使用API Kitchen发送POST请求以及它发送的标头
Status: 200
X-Powered-By: PHP/5.3.2-1ubuntu4.11
Server: Apache/2.2.14 (Ubuntu)
Content-Type: application/xml
Date: Fri, 10 Feb 2012 11:00:43 GMT
Keep-Alive: timeout=15, max=100
Content-Length: 936
Connection: Keep-Alive
我无法从中看到编码是什么.
编辑3:
编码是application / x-www-form-urlencoded,这可能是问题所在!我该如何具体说明这应该是什么?
编辑2:
$this-> request->方法包含’post’
解决方法:
感谢所有的帮助,事实证明,为了工作,请求的内容类型必须是application / xml,而不是application / x-www-form-urlencoded.
标签:php,rest,http-headers,codeigniter
来源: https://codeday.me/bug/20190621/1251140.html