我有两条路线。
Route::get('/receiveSignal', 'SignalController@receiveSignal');
Route::get('/sendSignal', 'SignalController@sendSignal');
我想模拟从sendSignal
向接收信号路径发送数据。
所以,在发送信号功能时,我有这个:
public function sendSignal()
{
$data = ['spotid' => '421156', 'name' => 'Test', 'desc' => 'some desc', 'StartofDetection' => '2018-01-17 22:22:22'];
$dataJson = json_encode($data);
return $dataJson;
}
如何将其更改为receiveSignal
,如下所示:
public function receiveSignal()
{
$test = file_get_contents('php://input');
dd($test);
}
在我输入http://localhost:8000/sendSignal后,我应该在receiveSignal
收到json。这有可能吗?
答案 0 :(得分:0)
尝试这样的事情: 1.在你的路线:
Route::post('receiveSignal', 'SignalController@receiveSignal');
Route::get('sendSignal', 'SignalController@sendSignal');
在您的sendSignal方法
中public function sendSignal() { $data = ['key' => 'value', 'key2' => 'value2']; $response = http_post_fields('http://localhost:8000/receiveSignal', $data); if (!empty($response)) { return view('success'); // or anything else you want to return } else { return view('failed'); } }
在您的receiveSignal方法
中public function receiveSignal(Request $request) { $key = $request->input('key'); $key1 = $request->input('key2'); //and so on }