您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 牡丹江分类信息网,免费分类信息发布

在Laravel中如何获取HTTP请求体的内容?

2024/4/14 11:31:22发布22次查看
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 −
example 1的翻译为:示例 1using $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)
example 2的中文翻译为:示例2using $request->collect() method.
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] =>)
example 3使用 $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

example 4使用 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请求体的内容?的详细内容。
牡丹江分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录