我开发了一个symfony2 restful后端,本地一切都有效。
所以我在apache2服务器上部署了应用程序(由directadmin包装),出现了奇怪的错误:
基本上当我发送DELETE(甚至PUT / POST取决于api)时,服务器会像GET一样响应。
为了更好地解释这个问题,我粘贴了curl cmd的日志:
$ curl -X DELETE website/api/sign/ -H "apiKey:7WJiHShAYPBI0asK1ZaKlJzpnn550X08" -v
* Hostname was NOT found in DNS cache
* Trying <ip here>...
* Connected to www.website.com (<ip here>) port 80 (#0)
> DELETE /api/sign/ HTTP/1.1
> User-Agent: curl/7.35.0
> Host: www.website.com
> Accept: */*
> apiKey:7WJiHShAYPBI0asK1ZaKlJzpnn550X08
>
< HTTP/1.1 200 OK
< Date: Sun, 29 Mar 2015 16:13:07 GMT
* Server Apache/2 is not blacklisted
< Server: Apache/2
< X-Powered-By: PHP/5.3.16
< Cache-Control: no-cache
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE
< Access-Control-Allow-Headers: X-Requested-With, origin, content-type, accept, apiKey
< X-Symfony-Cache: GET /api/sign/: miss
< Vary: Accept-Encoding,User-Agent
< Content-Length: 279
< Content-Type: application/json
然后内容是相对于GET请求的内容...
实际上不知道为什么,但我已经添加了所有OPTIONS api。
答案 0 :(得分:1)
解决方案:
http://forum.directadmin.com/showthread.php?t=35402
问题只是在httpd
中禁用了PUT和DELETE 以这种方式改变httpd.conf解决了这个问题:[old httpd.conf]
<Directory /home/*>
AllowOverride All
Options -MultiViews -Indexes FollowSymlinks IncludesNoExec +Includes
<Limit GET POST OPTIONS PROPFIND>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS PROPFIND>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
和
[new httpd.conf]
<Directory /home/*>
AllowOverride All
Options -MultiViews -Indexes FollowSymlinks IncludesNoExec +Includes
<Limit GET POST OPTIONS PROPFIND PUT DELETE>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS PROPFIND PUT DELETE>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>