我刚刚使用GET
方法注册了一个自定义WordPress终结点,并且工作正常,但是如果我对POST
做同样的事情,它将找不到路由。
我已经完全尝试了每个人所说的方法。 WP_REST_Server::CREATABLE
,POST
和post
。似乎没有一个起作用,这对我来说毫无意义,因为我认为GET
和POST
之间的区别不应该使一个起作用,而对其他却没有作用。
add_action( 'rest_api_init', function(){
register_rest_route('x/v1/', 'x', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'get_user_folder_id',
)
);
});
add_action( 'rest_api_init', function(){
register_rest_route('x/v1/', 'x/', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => 'post_user_folder_id',
'show_in_rest' => true,
)
);
});
我希望在使用邮递员时找到路线,我只是在回声一个字符串。
我的答复是:
{
"code": "rest_no_route",
"message": "No route was found matching the URL and request method",
}