无法将本机应用程序(expo)与flask服务器连接

2024-05-13 00:19:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将我的expo应用程序连接到flask服务器

这是请求

 fetch("127.0.0.1:5000/post", {
            method: 'POST',
            body: {
                'base64' : photoData["base64"]
            },
        })
        .then(response => response.json())
        .then(result => {
            console.log("******************\nRESULT");
            console.log(result);
            })
        .catch(err => { console.log(err); })

在服务器端。我已经试着用邮递员发送请求,一切都成功了

@app.route('/post', methods=['Post'])
def webhook():
    file = request.args['base64']
    rv = base64.b64encode(str.encode(file))  # bytes
    rv = rv.decode('ascii')  # str
    return rv

这是我在世博会上犯的错误

Network request failed
- node_modules\whatwg-fetch\dist\fetch.umd.js:535:17 in setTimeout$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:383:16 in callTimers
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue

有人知道解决办法吗


Tags: inlogmodulesnodelibrariesjsfetchpost