uni-app鸿蒙app在h5中不能进行局域网请求

uni-app鸿蒙app在h5中不能进行局域网请求

在uni中使用局域网内请求{“url”:“http://192.168.11.1:8085”} 返回错误:“error”:{“errMsg”:“request:fail Server returned nothing (no headers, no data)”} 疑似请求被拦截发不出去;

在原生中局域网内进行http请求成功;外网进行https请求原生和uni都可以成功;

图片 图片


更多关于uni-app鸿蒙app在h5中不能进行局域网请求的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于uni-app鸿蒙app在h5中不能进行局域网请求的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


这是一个常见的跨域安全限制问题。在H5环境下,浏览器会遵循同源策略,直接请求局域网IP地址会被拦截。建议采取以下解决方案:

  1. 使用uni-app的代理配置: 在manifest.json中添加:
"h5": {
  "devServer": {
    "proxy": {
      "/api": {
        "target": "http://192.168.11.1:8085",
        "changeOrigin": true
      }
    }
  }
}
  1. 如果是生产环境,需要后端配合:
  • 配置CORS允许跨域
  • 或者通过nginx反向代理
  1. 也可以考虑使用uni.request的withCredentials参数:
uni.request({
  url: 'http://192.168.11.1:8085',
  withCredentials: true
})
回到顶部