Kohana Restful Put

时间:2016-09-12 08:59:53

标签: rest kohana kohana-3.3

我有一个问题,放入kohana restfull api。 它看起来像我的$ post不起作用,因为在我使用此功能后,我只能看到未找到数据!'。任何的想法?感谢帮助。  这是我的代码。

      int userValue, rad, heightOfRectangle, widthOfRectangle, baseOfTriangle, heightOfTriangle;
        double area = 0;

        Console.Write("\n\n");
        Console.Write("Calculating Area of Geometrical Shape\n");
        Console.Write("=======================================\n");
        Console.Write("\n\n");
        Console.Write("Please select 1 for Circle, 2 for Rectangle and 3 for Triangle: ");

        userValue = Convert.ToInt32(Console.ReadLine());

        switch (userValue)
        {
            case 1:
                Console.Write("Please Enter Radius of Circle: ");
                rad = Convert.ToInt32(Console.ReadLine());
                area = 3.14 * rad * rad;
                break;

            case 2:
                Console.Write("Please enter Height of Rectangle: ");
                heightOfRectangle  = Convert.ToInt32(Console.ReadLine());
                Console.Write("Please enter Width of Rectangle: ");
                widthOfRectangle = Convert.ToInt32(Console.ReadLine());
                area = widthOfRectangle * heightOfRectangle;
                break;

            case 3:
                Console.Write("Please enter Base of Triangle: ");
                baseOfTriangle = Convert.ToInt32(Console.ReadLine());
                Console.Write("Please enter height of Triangle: ");
                heightOfTriangle = Convert.ToInt32(Console.ReadLine());
                area = .5 * baseOfTriangle * heightOfTriangle;
                break;

        }

        Console.WriteLine("\nThe area is {0}", area);

1 个答案:

答案 0 :(得分:0)

您可以使用此Kohana模块与Restfull API配合使用。它有处理PUT,UPDATE方法的方法 https://github.com/SupersonicAds/kohana-restful-api

您可以使用

$this->request->query (); 
$this->request->body ();

如果在query()中收到参数,那么它可以使用它的数组,或者如果你在body()中请求是RAW请求,那么你可以使用parse_str函数将它转换为数组。

这是我的例子

class Controller_RestTest extends Controller_REST {
    public function action_index() {
    }
    public function action_update() {
        echo Debug::vars ( $this->request->query () );
        echo Debug::vars ( $this->request->body () );
    }
}

并且对于这个PUT请求我得到了这个回复

PUT http://localhost/RestTest?a=1234&b=4567
Content-Type: application/x-www-form-urlencoded
?body-contents=this is boy contents
 -- response --
200 OK
Server:  nginx
Date:  Tue, 11 Oct 2016 11:43:44 GMT
Content-Type:  text/html; charset=utf-8
Content-Length:  158
Connection:  keep-alive
Cache-Control:  no-cache, no-store, max-age=0, must-revalidate
Vary:  Accept-Encoding
Content-Encoding:  gzip
X-Powered-By:  PHP/5.6.26




array(2) (
    "a" => string(4) "1234"
    "b" => string(4) "4567"
)

string(35) "?body-contents=this is boy contents"