0
我有一個問題來獲取PUT請求數據。無法獲取PUT參數Phalcon Oauth2服務器
我按照這個框架項目: Phalcon-api-oauth2
當我發送PUT請求, 結果總是空數組()
我曾嘗試改變了一些代碼:
micro.php
之前
public function setRoutes($file) {
if (!file_exists($file)) {
throw new \Exception('Unable to load routes file');
}
$routes = include($file);
if (!empty($routes)) {
foreach($routes as $obj) {
switch($obj['method']) {
case 'get':
$this->get($obj['route'], $obj['handler']);
break;
case 'post':
$this->post($obj['route'], $obj['handler']);
break;
case 'delete':
$this->delete($obj['route'], $obj['handler']);
break;
case 'put':
$this->head($obj['route'], $obj['handler']);
break;
case 'options':
$this->options($obj['route'], $obj['handler']);
break;
case 'patch':
$this->patch($obj['route'], $obj['handler']);
break;
default:
break;
}
}
}
}
之後
public function setRoutes($file) {
if (!file_exists($file)) {
throw new \Exception('Unable to load routes file');
}
$routes = include($file);
if (!empty($routes)) {
foreach($routes as $obj) {
switch($obj['method']) {
case 'get':
$this->get($obj['route'], $obj['handler']);
break;
case 'post':
$this->post($obj['route'], $obj['handler']);
break;
case 'delete':
$this->delete($obj['route'], $obj['handler']);
break;
case 'put':
$this->put($obj['route'], $obj['handler']);
break;
case 'options':
$this->options($obj['route'], $obj['handler']);
break;
case 'patch':
$this->patch($obj['route'], $obj['handler']);
break;
default:
break;
}
}
}
}
我在
供應商增加了新的方法,用於PUT請求/ OAuth2用戶/ SRC/OAuth2用戶/服務器/存儲/ PDO/MySQL的/ Request.php
public function put($index = NULL)
{
// print_r($this->request->getPut()); // I can see the PUT request data here
return $this->request->getPut($index);
}
也添加在
供應商/聯盟/的oauth2服務器/ src目錄/聯盟/ OAuth2用戶/服務器/的Util/RequestInterface.php
public function put($index = null);
然後修改這個類
供應商/聯盟/的oauth2服務器/ src目錄/聯盟/ OAuth2用戶/服務器/的Util/Request.php
class Request implements RequestInterface
{
protected $get = array();
protected $post = array();
protected $cookies = array();
protected $files = array();
protected $server = array();
protected $headers = array();
protected $put = array(); // new property added
// new $put parameter added */
public function __construct(array $get = array(), array $post = array(), array $put = array(), array $cookies = array(), array $files = array(), array $server = array(), $headers = array())
{
$this->get = $get;
$this->post = $post;
$this->put = $put;
$this->cookies = $cookies;
$this->files = $files;
$this->server = $server;
if (empty($headers)) {
$this->headers = $this->readHeaders();
} else {
$this->headers = $this->normalizeHeaders($headers);
}
}
/* new method added */
public function put($index = null, $default = null)
{
return $this->getPropertyValue('put', $index, $default);
}
....
任何人都可以請讓我知道什麼是錯的代碼?
乾杯。
是否是一個區分大小寫的問題? –
@JamesFenwick我不這麼認爲,似乎oauth服務器的庫取代了getPut()函數的實際價值。 –