POST 请求在 Heroku 环境中被视为 GET [英] POST request treated as GET in Heroku environment
问题描述
我有奇怪的情况.我有一个 RoR 应用程序,它提供了我从 Java 应用程序连接到的 REST API.
I have weird case. I have a RoR app, which provides REST API which I'm connecting to from Java application.
我正在本地开发 RoR,并将其部署在 Heroku 环境中.
I'm developing RoR locally, and deploying it on Heroku environment.
不管如何(我从 Java APP、Mozilla REST 客户端等尝试)我尝试发送 POST HTTP 请求,该请求应该由 api 控制器中的创建操作处理.在本地主机上 - 一切都按预期工作.在 Heroku 生产环境中 - POST 请求被视为正常的 GET.
Regardless how (I tried from Java APP, Mozilla REST client, etc.) I try to send POST HTTP request that should be handled by create action in api controller. On localhost - everything is working as expected. On Heroku production env - the POST request is treated as normal GET.
这是我对这个资源的路线:
Here are my routes for this resource:
api_v1_items GET /api/v1/items(.:format) api/v1/items#index {:format=>:json}
POST /api/v1/items(.:format) api/v1/items#create {:format=>:json}
api_v1_item GET /api/v1/items/:id(.:format) api/v1/items#show {:format=>:json}
PATCH /api/v1/items/:id(.:format) api/v1/items#update {:format=>:json}
PUT /api/v1/items/:id(.:format) api/v1/items#update {:format=>:json}
DELETE /api/v1/items/:id(.:format) api/v1/items#destroy {:format=>:json}
所以我正在尝试向 /api/v1/items
发送 POST 请求并传递所有必要的参数.
So I'm trying to do POST request to /api/v1/items
passing all necessary parameters.
在本地主机响应是正确的:
In localhost the response is correct:
Started POST "/api/v1/items?token=l4XOHrhDApPqTp1u4TxBjQ" for 127.0.0.1 at 2014-05-15 22:11:49 +0200
Processing by Api::V1::ItemsController#create as JSON
Parameters: {"height"=>10.0, "item_name"=>"Super item", "width"=>20.0, etc...
但是,在 Heroku 上发出的相同请求被视为 GET:
However the same request fired at Heroku its treated as GET:
2014-05-15T20:27:58.137541+00:00 app[web.1]: Started GET "/api/v1/items?token=iEdDkDLiDUlWi0mDbr6XYw" for 89.74.57.51 at 2014-05-15 20:27:58 +0000
2014-05-15T20:27:58.223620+00:00 app[web.1]: Processing by Api::V1::ItemsController#index as JSON
有什么想法吗?当然,两个仓库是同步的.检查了几次.
Any idea? Of course both repos are in sync. Checked few times.
这真的很奇怪……也许是某种 Heroku 缓存魔法?
This is really weird... maybe some kind of Heroku cache magic?
推荐答案
HTTP/1.1 301 永久移动
HTTP/1.1 301 Moved Permanently
301 重定向不是 Heroku 魔法.您的 DNS(或可能是您的应用)可能会将所有顶点请求 (mydomain.com) 转发到 www
子域.
301 redirects are not Heroku magic. Your DNS (or possibly your app) is likely forwarding all apex requests (mydomain.com) to the www
subdomain.
首选使用子域:
这篇关于POST 请求在 Heroku 环境中被视为 GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!