0

我正在使用Codeigniter 3.1.0,从这里下载的Restserver 以及这里文档。我也在使用 Chrome 的扩展Postman

问题是,即使我从 Postman 的下拉菜单中选择 POST,它也会命中 get 方法......下面是代码:

defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';

class Example extends REST_Controller {
    function __construct() {
        parent::__construct();
    }
    public function users_get() {
        echo "get request";
    }
    public function users_post() {
        echo "post request";
    }
}

现在通过 Postman,如果我选择GET到 URL example-domain.com/api/example/users预览是获取请求

如果我选择POST到相同的 URL example-domain.com/api/example/users预览再次获取请求而不是发布请求

我没有更改config/rest.php中的任何内容,我正在使用控制器/api/example中已实现的 Restserver 示例

有谁知道为什么我不能点击 POST 方法?

4

1 回答 1

1

Finally i found what caused the issue. I had previously installed SSL on this domain but i was trying to call the API with HTTP.

In .htaccess i had the rewriterule

RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

to force HTTPS.

If i make a POST request with HTTPS it works like a charm.

If i make a POST request with HTTP it redirects to HTTPS (because of the rewrite rule), therefore there is a new GET request to the new page.

于 2016-10-25T07:38:59.323 回答