dongwu8064
2016-03-02 21:19
浏览 212
已采纳

方法名称作为Laravel API中的POST参数

I want to make Laravel RESTful API and also i have something that can send request to www but there is problem - this THING can send only GET and POST. Is there way to configure Laravel to know that i sent method name as a parameter for ex. in _method parameter and redirect to proper Route (i prefer making Route::resource so that's why i'm asking)?

图片转代码服务由CSDN问答提供 功能建议

我想制作Laravel RESTful API,我也有一些东西可以向www发送请求但是有问题 - 这个 THING只能发送GET和POST。 有没有办法配置Laravel知道我发送方法名作为ex的参数。 在_method参数中并重定向到正确的Route(我更喜欢使用Route :: resource这就是我要问的原因)?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtqf81594 2016-03-03 05:29
    已采纳

    This is called Method Tunneling through POST.

    In many scenarios clients are limited to the HTTP GET and POST methods only. In order to help work-around this limitation, RESTful servers can support method tunneling through POST. The methods that can be executed through tunneling are MERGE, PUT and DELETE.

    To issue a request with method tunneling a client sets up a request with body and headers as needed, but uses POST as the HTTP method instead of the actual required one. It then adds one more header, "X-HTTP-Method", and gives it the value MERGE, PUT or DELETE.

    Servers must check if POST requests have the X-HTTP-Method header set to one of the valid values and if so execute the rest of the request as if the header value was the actual HTTP method for it.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题