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)?
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.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报