to get the details of the http request you need to make use of the class illuminate\http\request.
使用上面的类,您将能够从HTTP请求中获取输入、cookies和文件。现在考虑以下表单 -

To get all the details from the HTTP request you can do as follows −
Using $request->all() method
在下面的表单中输入以下详细信息:

Once you submit it will retrieve all the input data and return an array with data.
public function validateform(Request $request) {
$input = $request->all();
print_r($input);
}
The output of the above code is −
Array ( [_token] => 367OQ9dozmWlnhu6sSs9IvHN7XWa6YKpSnnWrBXx [name] => Rasika Desai [email] => rasika@gmail.com [age] => 20 [address] => Pune )
Using $request->collect() method.
里面有2个文件夹。其中这个文件名是:finishing,是我项目还没有请求后台的数据的模拟写法。请求后台数据之后,瀑布流的js有一点点变化,放在文件名是:finished。变化在于需要穿参数到后台,和填充的内容都用后台的数据填充。看自己项目需求来。由于chrome模拟器是不允许读取本地文件json的,所以如果你要进行测试,在hbuilder打开项目就可以看到效果啦,或者是火狐浏览器。
92
This method will return the data as a collection.
public function validateform(Request $request) {
$input = $request->collect();
print_r($input);
}
The output of the above code is −
Illuminate\Support\Collection Object (
[items:protected] => Array(
[_token] => 367OQ9dozmWlnhu6sSs9IvHN7XWa6YKpSnnWrBXx
[name] => Rasika Desai
[email] => rasika@gmail.com
[age] => 20
[address] => Pune
)
[escapeWhenCastingToString:protected] =>
)
使用 $request->getContent() 方法。
此方法将输出为URL查询字符串,数据以键/值对的形式传递。
public function validateform(Request $request) {
$input = $request->getContent();
echo $input;
}
The output of the above code is
_token=367OQ9dozmWlnhu6sSs9IvHN7XWa6YKpSnnWrBXx&name=Rasika+Desai&email=rasika%40gmail.com&age=20&address=Pune
使用 php://input
这将返回来自URL查询字符串中输入字段的数据。
$data = file_get_contents('php://input');
print_r($data);
The output of the above code is −
_token=367OQ9dozmWlnhu6sSs9IvHN7XWa6YKpSnnWrBXx&name=Rasika+Desai&email=rasika%40gmail.com&age=20&address=Pune
以上就是在Laravel中如何获取HTTP请求体的内容?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号