簡體   English   中英

405方法不允許使用Restler

[英]405 Method not allowed using Restler

我對Restler有問題:我正在創建自己的API,以便從其他網站訪問我的數據。 當我嘗試向我的API發送POST請求時,它說:

{
    error: {
        code: 405
        message: "Method Not Allowed"
    }
    debug: {
        source: "Routes.php:422 at route stage"
        stages: {
            success: [1]
                0:  "get"

            failure: [3]
                0:  "route"
                1:  "negotiate"
                2:  "message"
        }
    }
}

我的index.php代碼是:

<?php
require_once 'vendor/restler.php';
use Luracast\Restler\Restler;
$r = new Restler();
$r->addAPIClass('v1'); // repeat for more
$r->handle(); //serve the response

我已經嘗試過:

header('Access-Control-Allow-Methods: *');

但是什么都沒有。 有人可以幫忙嗎?

為了讓Restler接受POST請求,必須在v1類中實現post函數。

一個典型的例子可以是:

function post($request_data = NULL){
   $result = new stdClass();
   $result->sometitle = 'OK';
   return $result;
}

其中$request_data是帶有您傳遞的POST參數的數組。

僅在POST方法上可訪問此函數,它將返回:

{
  "sometitle ": "OK"
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM