Javascript react native不从外部可见的flask服务器获取内容-“;“网络请求失败”;论发展
我有一个本地flask服务器,它运行文档中指定的configJavascript react native不从外部可见的flask服务器获取内容-“;“网络请求失败”;论发展,javascript,python-3.x,react-native,http,flask,Javascript,Python 3.x,React Native,Http,Flask,我有一个本地flask服务器,它运行文档中指定的configflask-host:0.0.0。当我从react native调用flask服务器时,我没有从flask服务器接收响应,而是收到以下错误: - node_modules\react-native\Libraries\vendor\core\whatwg-fetch.js:504:29 in onerror - node_modules\event-target-shim\lib\event-target.js:172:43 in di
flask-host:0.0.0
。当我从react native调用flask服务器时,我没有从flask服务器接收响应,而是收到以下错误:
- node_modules\react-native\Libraries\vendor\core\whatwg-fetch.js:504:29 in onerror
- node_modules\event-target-shim\lib\event-target.js:172:43 in dispatchEvent
- ... 8 more stack frames from framework internals"
我发现的所有关于此问题的示例都有人使用“localhost”,这不是我正在做的,并且故障排除步骤也不起作用。我正在使用expo,它正在处理下面调用中的“fetch”函数。这还没有运行任何android或ios特定的应用程序,因为代码仍处于早期阶段
响应本机呼叫:
export function get_page(){
url = 'http://<local ipv4 address>:5000/'
return fetch(url)
.then((response)=>{
console.log(response)
return response
})
.catch((error) =>{
console.log(error)
return error
})
}
同样,我只是在尝试连接一段时间后才收到网络错误。当我从firefox或python的IDLE访问URL时,我可以看到该页面,这意味着这完全是我的react本机环境的问题。我们将一如既往地感谢您的帮助。这是网络许可。如今,android和ios不允许HTTP连接默认设置 对于Android,必须在AndroidMainfest.xml中添加networkSecurityConfig
<application
...
networkSecurityConfig="@xml/networkConfig"
.../>
//the config content like below
<network-security-config>
//one way allow all http connection
<base-config cleartextTrafficPermitted="true"/>
// the other way allow some fixed url
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
</domain-config>
</network-security-config>
//配置内容如下所示
//单向允许所有http连接
//另一种方法允许一些固定的url
本地服务器
对于ios,您应该在info.plist中添加地址
<key>address</key>
<dict>
<key>NSExceptionAllowsInsecuredHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
地址
NSExceptionAllowsInsecuredHTTPLoads
NSExceptionRequiresForwardSecretary
n包括多个域
可能会看到
<key>address</key>
<dict>
<key>NSExceptionAllowsInsecuredHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>