You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo环境下如何启用HTTP请求?(无需生成原生文件夹)

解决Expo 49环境下Google Play打包后HTTP请求被禁止的问题

你的问题根源是Android默认拦截明文HTTP流量,而你之前的Expo配置路径错误导致不生效,以下是两种可行的解决方案:

方案一:使用自定义网络安全配置文件

  1. 将你的network_security_config.xml文件放在项目根目录,内容保持不变:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>
  1. 修改app.json,将networkSecurityConfig字段直接放在android节点下(而非android.config子节点):
"expo": {
  // 其他配置项...
  "android": {
    "networkSecurityConfig": "./network_security_config.xml",
    // 其他Android配置...
  }
}

方案二:通过Expo插件快速启用明文流量(无需手动维护XML)

这种方式更简洁,不需要编写额外的XML文件:

  1. 安装expo-build-properties插件:
npx expo install expo-build-properties
  1. 在app.json中配置插件,开启明文流量允许:
"expo": {
  // 其他配置项...
  "plugins": [
    [
      "expo-build-properties",
      {
        "android": {
          "cleartextTrafficPermitted": true
        }
      }
    ]
  ],
  "android": {
    // 其他Android配置...
  }
}

注意事项

  • 优先使用HTTPS接口,明文HTTP存在安全风险,仅在必要场景下开启cleartextTrafficPermitted。
  • 修改配置后,重新构建用于Google Play的APK包即可生效。

内容的提问来源于stack exchange,提问作者Joao-gabriel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 09:15:21