【发布时间】:2014-07-04 11:32:30
【问题描述】:
我有奇怪的情况。我有一个 RoR 应用程序,它提供了我从 Java 应用程序连接到的 REST API。
我正在本地开发 RoR,并将其部署在 Heroku 环境中。
无论如何(我尝试从 Java APP、Mozilla REST 客户端等)我尝试发送应该由 api 控制器中的创建操作处理的 POST HTTP 请求。在本地主机上 - 一切都按预期工作。在 Heroku 生产环境中 - POST 请求被视为普通 GET。
这是我获取此资源的路线:
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 请求,并传递所有必要的参数。
在 localhost 中响应是正确的:
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:
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
有什么想法吗?当然,两个仓库是同步的。检查了几次。
这真的很奇怪......也许是某种 Heroku 缓存魔法?
【问题讨论】:
-
你能用 curl 重现这个,并发布你的例子吗?
-
感谢您激励我使用 curl,解决方案如下。
-
我遇到了类似的问题:我发帖到
myapp.heroku.com而不是myapp.herokuapp.com——发帖到后者解决了这个问题。不过,从myapp.heroku.com获取是可以的。
标签: ruby-on-rails http post heroku get