Laravel如何处理来自浏览器的PUT请求? [英] How does Laravel handle PUT requests from browsers?
问题描述
我知道浏览器仅支持 POST
和 GET
请求,而Laravel使用以下代码支持 PUT
请求:
I know browsers only support POST
and GET
requests, and Laravel supports PUT
requests using the following code:
<?= Form::open('/path/', 'PUT'); ?>
... form stuff ...
<?= Form::close(); ?>
这将产生以下HTML
This produces the following HTML
<form method="POST" action="http://example.com/home/" accept-charset="UTF-8">
<input type="hidden" name="_method" value="PUT" />
... form stuff ...
</form>
框架如何处理?它会在 之前捕获 POST
请求,并决定将请求发送到哪个路由吗?它是否使用ajax将实际的 PUT
发送到框架?
How does the framework handle this? Does it capture the POST
request before deciding which route to send the request off to? Does it use ajax to send an actual PUT
to the framework?
推荐答案
它插入一个隐藏字段,并且该字段提到它是PUT或DELETE请求
It inserts a hidden field, and that field mentions it is a PUT or DELETE request
echo Form::open('user/profile', 'PUT');
导致:
<input type="hidden" name="_method" value="PUT">
然后,当在 request.php
核心文件中进行路由时,它会寻找_method(在代码中查找欺骗"),并且如果检测到,将使用该值路由至正确宁静的控制器.
Then it looks for _method when routing in the request.php
core file (look for 'spoofing' in the code) - and if it detects it - will use that value to route to the correct restful controller.
它仍在使用"POST"为了达成这个.没有使用ajax.
It is still using "POST" to achieve this. There is no ajax used.
这篇关于Laravel如何处理来自浏览器的PUT请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!