DooPHP IRC channel


如何得到PUT请求的原始数据?

DooPHP 中文讨论区

如何得到PUT请求的原始数据?

Postby wingyiu » Sat Nov 26, 2011 4:57 am

Code: Select all
$route['put']['/user/update/:uid'] = array('UserController', 'update');

Code: Select all
function update(){
      echo file_get_contents("php://input");
      print_r($this->params);
      print_r($this->puts);
      
      print_r($_SERVER);
   }

当用CURL发送的PUT请求是XML格式数据时
Code: Select all
curl -X PUT -H "Content-Type:text/xml" -d "<xml></xml>" "http://***.***.***。***/kcitizen/user/update/5"

输出:
Code: Select all
Array
(
    [uid] => 5
)
Array
(
    [<xml></xml>] =>
)
Array
(
    [REDIRECT_HTTP_AUTHORIZATION] =>
    [REDIRECT_STATUS] => 200
    [HTTP_AUTHORIZATION] =>
    [HTTP_USER_AGENT] => curl/7.22.0 (i386-pc-win32) libcurl/7.22.0 zlib/1.2.5
    [HTTP_HOST] => 125.216.242.44
    [HTTP_ACCEPT] => */*
    [CONTENT_TYPE] => text/xml
    [CONTENT_LENGTH] => 11
    ...
    [REDIRECT_URL] => /kcitizen/user/update/5
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => PUT
    [QUERY_STRING] =>
    [REQUEST_URI] => /kcitizen/user/update/5
    [SCRIPT_NAME] => /kcitizen/index.php
    [PHP_SELF] => /kcitizen/index.php

)

看来一下源码
Code: Select all
public function initPutVars(){
        parse_str(file_get_contents('php://input'), $this->puts);
    }

貌似doophp只能处理content-type为application/x-www-form-urlencoded格式的PUT请求,无法处理XML等格式的数据,而且也无法取得原始的请求实体的内容,这对于显然无法满足RESTful webservice的需求啊!
求解决
wingyiu
 
Posts: 2
Joined: Sat Nov 26, 2011 4:46 am

Return to Chinese

Who is online

Users browsing this forum: No registered users and 1 guest