我正在尝试从iPad访问本地Web服务器(flask)。
我的设置:iPad通过以太网连接到Macbook(服务器)。
当我尝试使用Node.js(快速)网络服务器(如下所示)时,它可以工作,我可以访问http://172.x.x.x:5000/
并获取响应。但是,当我使用简单的flask服务器尝试相同操作时,却无法访问它,我在iPad(Chrome浏览器)上收到错误ERR_CONNECTION_CLOSED
。
可以运行的简单Node.js服务器:
const express = require('express');
var app = express();
var PORT = 5000;
app.get('/',(req,res) => {
res.send(JSON.stringify({ value: 1 }));
})
app.listen(PORT);
可在本地运行但不能在iPad上运行的flask(Python)服务器:
from flask import flask
app = flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run(host='0.0.0.0',port=5000,debug=False)
详细信息:如果我将ssl_context添加到flask(app.run(ssl_context='adhoc'
),则可以在iPad上运行,但是我没有凭据,并且收到不安全网页的错误,因此对REST API的请求无效。
obs:我无法在生产中运行node.js。
感谢您的帮助!