无法获取PUT参数Phalcon Oauth2服务器


Cannot get PUT parameter Phalcon Oauth2 server

获取PUT请求数据有问题。

我遵循这个框架项目: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;
            }
        }
    }
}

我在
vendor/Oauth2/src/Oauth2/Server/Storage/Pdo/Mysql/request .php中添加了新的PUT请求方法

public function put($index = NULL)
{
    // print_r($this->request->getPut()); // I can see the PUT request data here
    return $this->request->getPut($index);
}


供应商/联赛/oauth2-server/src//OAuth2/服务器/Util/RequestInterface.php

 public function put($index = null);

然后修改这个类
供应商/联赛/oauth2-server/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);
}
....

谁能告诉我代码出了什么问题?

欢呼。

您是否能够更改PUT请求的Content-Type ?

我在PUT参数中遇到了类似的问题,并通过使用Content-Type: application/x-www-form-urlencoded来解决。尝试将其添加到Request类的头数组中。