我在Laravel有一个邮政路线,所以如果用户将数据发布到路线我想要添加数据请求然后将其发布到我有的另一个邮政路线然后向用户显示我从第二条路线获得的结果。
有办法吗?或者我应该使用GuzzleHttp?
答案 0 :(得分:0)
You can use curl to perform the sub request.
Route::any('/proxy', function (Request $request) {
//Get all of the input from the request and store them in $data.
$data = $request->all();
//initialise your other data.
$data2 = ['xyz' => "xyz"];
$newPayload = array_merge($data, $data2);
$endPoint = "https://example.org";
$ch = curl_init($endPoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $newPayload);
// execute!
$response = curl_exec($ch);
// close the connection, release resources used
curl_close($ch);
return (string)$response;
});