超薄框架和GET / PUT / POST方法 [英] Slim framework and GET/PUT/POST methods
问题描述
例如,我用这个code测试路线:
$ APP-GT&;得到('/ API',函数(){
呼应搞定!;
});
$ APP-GT&;后期('/ API',函数(){
回声'后';
});
$ APP-GT&;把('/ API',函数(){
回声放!;
});
有关API测试我使用RESTClient实现插件的Chrome。
当我尝试做得到请求,响应是搞定了!。其良好的。
不过:</ P>
-
当我尝试做POST请求,响应也就是搞定了!。为什么?它必须是岗位!
-
当我尝试做PUT请求,(在响应头:允许:GET,HEAD,POST,OPTIONS,TRACE)超薄反应有405错误(不允许的方法)与消息:
的请求的方法PUT是不允许的URL / API。
块引用>我在做什么错了?
解决方案确保您的
的.htaccess
是以下(从的 codeguy /修身):RewriteEngine叙述在#有些主机可能需要您使用`RewriteBase`指令。
#如果你需要使用`RewriteBase`指令,它应该是
#包含此htaccess文件的目录的绝对物理路径。
#
#的RewriteBase /的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^的index.php [QSA,L]For example, i use this code for testing routes:
$app->get('/api', function () { echo 'get!'; }); $app->post('/api', function () { echo 'post!'; }); $app->put('/api', function () { echo 'put!'; });
For api testing i use RestClient plugin for Chrome.
When i try do GET request, response is 'get!'. Its good.
But:
When i try do POST request, response also is 'get!'. Why? Its must be 'post!'.
When i try do PUT request, (in Response Headers: Allow: GET,HEAD,POST,OPTIONS,TRACE ) Slim response have 405 error (Method Not Allowed) with message:
"The requested method PUT is not allowed for the URL /api."
What am I doing wrong?
解决方案Be sure that your
.htaccess
is the following (from codeguy/Slim):RewriteEngine On # Some hosts may require you to use the `RewriteBase` directive. # If you need to use the `RewriteBase` directive, it should be the # absolute physical path to the directory that contains this htaccess file. # # RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L]
这篇关于超薄框架和GET / PUT / POST方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!