dongshan4316 2015-10-13 20:57
浏览 87

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

I have a problem to get PUT request data.

I follow this skeleton project : Phalcon-api-oauth2

when I send PUT request, the result always empty array()

I have tried changed the several code :

micro.php
before

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;
            }
        }
    }
}

after

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;
            }
        }
    }
}

I added new method for PUT request in
vendor/Oauth2/src/Oauth2/Server/Storage/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);
}

also added in
vendor/league/oauth2-server/src/League/OAuth2/Server/Util/RequestInterface.php

 public function put($index = null);

then modified this class
vendor/league/oauth2-server/src/League/OAuth2/Server/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);
}

....

can anyone please let me know what wrong with the code ?

Cheers.

  • 写回答

1条回答 默认 最新

  • dongmi5607 2015-12-15 21:26
    关注

    Are you able to change the Content-Type of the PUT request?

    I had a similar problem with PUT parameters and it was solved by using Content-Type: application/x-www-form-urlencoded. Try to add it to the headers array of the Request class.

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能