簡體   English   中英

無法從本地網絡中的其他設備訪問在mac上運行的http服務器

[英]Not able to access http server running on mac from other devices in local network

我使用節點js創建了一個http服務器(在我的mac機器上),它正在偵聽端口8081.我無法使用本地IP地址和端口從其他設備(例如我的手機)訪問此服務器。 我的筆記本電腦和手機都在同一個本地網絡(同一子網)。 如何在移動設備上訪問我的服務器。

以下是我的代碼段。

 var http = require("http"); http.createServer(function (request, response) { // Send the HTTP header // HTTP Status: 200 : OK // Content Type: text/plain response.writeHead(200, {'Content-Type': 'text/plain'}); // Send the response body as "Hello World" response.end('Hello World\\n'); }).listen(8081); 

要從另一台設備訪問localhost,您必須在Internet上公開您的端口,從而創建一個http隧道。 檢查我前一段時間給出的答案: 從localhost到網絡的Node.js應用程序

你需要找出你的Mac連接的IP地址示例192.1168.43.23,然后在那個ip上托管你的代碼,如http.createServer().listen(8081, 192.168.43.23);

然后在你的移動瀏覽器中打開網址192.168.43.23:8081,

這將成功

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM