我已经使用node 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);
发布于 2017-05-21 01:37:22
要从另一个设备访问localhost,您必须在internet上公开您的端口,从而创建一个http隧道。检查一下我之前给出的答案:Node.js app from localhost to the web
发布于 2017-05-21 01:43:29
您需要找出您的Mac连接到哪个IP地址上例如192.1168.43.23,然后在该ip上托管您的代码,如http.createServer().listen(8081, 192.168.43.23);
然后在您的移动浏览器192.168.43.23:8081中打开url,
这将会起作用
https://stackoverflow.com/questions/44088952
复制相似问题