我有一個 Power Delivery Unit 設備連接到我的本地網路,它由一個簡單的網頁控制,我正在嘗試使用 Laravel Schedule 在一天中的特定時間打開和關閉設備。因此,我使用以下方法創建了 PDUController:(兩種方法都可以正常作業)
public function on()
{
return redirect()->away(
"http://192.168.0.100/control_outlet.htm?outlet6=1&outlet7=1&op=0&submit=Apply"
);
}
public function off()
{
return Redirect::to(
"http://192.168.0.100/control_outlet.htm?outlet6=1&outlet7=1&op=1&submit=Apply"
);
}
如果您訪問路線:
Route::get('/pdu/on', [PDUController::class, 'on'])->name('pdu.on');
Route::get('/pdu/off', [PDUController::class, 'off'])->name('pdu.off');
一切都按預期作業,您可以相應地打開或關閉設備。現在,當我在 Kernel.php 上使用 Scheduler 時,例如:
protected function schedule(Schedule $schedule)
{
$schedule->call('App\Http\Controllers\PDUController@on')->everyMinute();
}
它不起作用。我知道流程是正確的,因為我可以正確地 Log::debug() 程序的每一步,但是設備沒有接收到信號,因此沒有打開。你能幫忙嗎?謝謝!
uj5u.com熱心網友回復:
重定向函式向瀏覽器回傳重定向回應。由于調度程式通過 Artisan 運行,因此沒有瀏覽器可以重定向,因此沒有建立連接。相反,使用HTTP 客戶端創建到頁面的連接。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/338006.html
