超薄框架和GET / PUT / POST方法 [英] Slim framework and GET/PUT/POST methods

查看:159
本文介绍了超薄框架和GET / PUT / POST方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我用这个code测试路线:

  $ APP-GT&;得到('/ API',函数(){
        呼应搞定!;
});
$ APP-GT&;后期('/ API',函数(){
        回声'后';
});
$ APP-GT&;把('/ API',函数(){
        回声放!;
});

有关API测试我使用RESTClient实现插件的Chrome。

当我尝试做得到请求,响应是搞定了!。其良好的。

不过:<​​/ P>


  1. 当我尝试做POST请求,响应也就是搞定了!。为什么?它必须是岗位!


  2. 当我尝试做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:

  1. When i try do POST request, response also is 'get!'. Why? Its must be 'post!'.

  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆