2015-02-08 133 views
2

例如,我使用此代码为测试路线:苗条框架和GET/PUT/POST方法

$app->get('/api', function() {       
     echo 'get!'; 
}); 
$app->post('/api', function() {        
     echo 'post!'; 
}); 
$app->put('/api', function() {       
     echo 'put!'; 
}); 

对于API测试我使用RESTClient实现插件铬。

当我尝试做GET请求时,响应是'get!'。这很好。

但是:

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

  2. 当我尝试做PUT请求,(在响应头:允许:GET,HEAD,POST,OPTIONS,TRACE)苗条响应具有405错误(不允许的方法)与消息:

“URL/api不允许请求的方法PUT”。

我在做什么错?

+0

它使用为我的作品[高级REST客户端(https://chrome.google.com/webstore/detail/advanced- rest-client/hgmloofddffdnphfgcellkdfbfbjeloo)和[DHC-REST/HTTP API客户端](https://chrome.google.com/webstore/detail/dhc-resthttp-api-client/aejoelaoggembcahagimdiliamlcdmfm)。你添加了''.htaccess''文件吗? – 2015-02-09 08:42:21

+0

是的,这是我的htaccess:! RewriteEngine叙述在 RewriteBase/ 的RewriteCond%{} REQUEST_FILENAME -f 的RewriteCond%{} REQUEST_FILENAME -d 重写规则^/$的index.php – hcuser 2015-02-09 11:12:31

+0

尝试使用[此(*)。酮](https://raw.githubusercontent.com/codeguy/Slim/master/.htaccess)。 – 2015-02-09 11:40:14

回答

4

确保您.htaccess如下(从slimphp/[email protected]):

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} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^index.php [QSA,L] 
+0

感谢您发布此信息。 Davide Pastore的链接对我来说不起作用,这是在拉出头发两天后终于使所有的东西都能够工作的。非常感激。 – ramijames 2017-02-19 06:57:39

+1

@ramijames感谢您的评论。我更新了我的答案,修复了断开的链接和'.htaccess'内容。 – 2017-02-19 11:55:25