【发布时间】:2012-03-02 20:34:26
【问题描述】:
我正在尝试用 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://input 只能读取一次,所以在设置变量之前执行var_dump(file_get_contents('php://input')) 表明我的 XML 数据正在从输入流中正确读取,但显然变量设置不正确。
但是var_dump($this->request->body) 只会输出NULL!有没有什么特殊的技术可以将php://input的内容存储在一个变量中?
编辑:
我正在使用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->method 包含'post'
【问题讨论】:
-
$this->request是什么类型的对象? -
$this->request被声明为protected $request = NULL; // Stores accept, language, body, headers, etc -
我找不到单独的实现或任何东西,第一次设置是在同一个构造函数中,并且设置为
$this->request->method = $this->_detect_method();。抱歉,我在这里似乎不是很有帮助! -
通过插入打印语句进行调试。并分解复合语句。
-
php://input不适用于 multipart/formdata 但您提到情况并非如此。然后你说$this->request->format打印NULL,你实际上是在做类似null and $a = 1;的事情,这意味着$a = ...;部分根本不执行!
标签: php codeigniter rest http-headers