0

Codeigniter 3.1.0を使用しています。Restserverは hereからダウンロードされ、ドキュメントhereからダウンロードされます。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 を介して、URL example-domain.com/api/example/usersへのGETを選択すると、プレビューはget requestになります

同じ URL example-domain.com/api/example/usersへのPOSTを選択すると、プレビューは再びリクエストを取得し、リクエストを投稿しません

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 に答える