[英]How can we call url() with port number in Laravel controller. Node server is running on different port that 8001 and Laravel port is 8000?
我的 Laravel 應用程序在127.0.0.1:8000 端口上運行,但我的節點服務器在端口 127.0.0.1:8001上運行,該端口有一個用於抓取數據的節點腳本。 如何調用 URL 函數從 Laravel 控制器中指出 127.0.0.1:8001 端口來運行這樣的腳本?
例如,檢查 DataScrapingController 中 index() 中的注釋
class DataScrapingController extends Controller
{
public function index()
{
// Here is the below URL I want to call this URL when a user calls this index
//controller function
"http://127.0.0.1:8001/scrape"
// After scraping the data when this **http://127.0.0.1:8001/scrape** URL call. which
// saves the data in the output.json file here I get the output.json file and return the
// data to the data-scraping blade file.
$data = json_decode(file_get_contents('output.json'));
return view('data-scraping', compact('data'));
}
}
下圖是 Laravel 應用程序中的節點層次結構
提前致謝
在 guzzle 周圍使用 Laravel Http 包裝器
$response = Http::get("http://127.0.0.1:8001/scrape");
請參閱https://laravel.com/docs/9.x/http-client#main-content
確保您沒有運行php artisan serve
因為它一次只能處理一個連接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.