环境信息:

DevEco Studio 5.1.1 Release
Windows 11.0
鸿蒙虚拟机是5.1.0版本的

问题:在虚拟机中运行的软件偶尔无法联网,日志例如:

[http_exec.cpp:318] CURLcode result 28
[http_exec.cpp:427] taskid=-2147483635, size:0, dns:0.000, connect:0.000, tls:0.000, firstSend:0.000, firstRecv:0.000, total:3012.467, redirect:0.000, errCode:2300028, RespCode:0, httpVer:0, method:GET, osErr:0
域名 http://www.baidu.com 解析失败: Timeout was reached

不管是TCP连接还是Webview全是失败,已经配置了网络权限如:

"requestPermissions": [
  {
    "name": "ohos.permission.INTERNET"
  }
]

还是失败.
网络是家庭网络,完全没有任何限制,也不需要显式指明代理就能正常上网.同时,打开设置中有个登录华为账号也是加载不出来,证明模拟器是完全没网的状态.
最诡异的是,有的时候模拟器还是正常上网,同样的网络同样的设置,没有任何更改.
检查代理中的测试连接全是正常,但是虚拟机完全无法连接.
0070086000317582543.20250911110850.63142396901044589820840821898425.png
0070086000317582543.20250911110949.64889080952643055926203210571523.png

解决过程

咨询客户工程师,让我使用最小代码做一个测试:

import webview from '@ohos.web.webview'

@Entry
@Component
struct web {
  private webviewController: WebviewController = new webview.WebviewController();
  url: string = "https://www.baidu.com"
  build() {
    Row() {
      Column() {
        Text(this.url)
        Web({
          src: this.url,
          controller: this.webviewController
        })
          .fileAccess(true) .javaScriptAccess(true) .domStorageAccess(true) .onlineImageAccess(true)
      }
      .width('100%')
    }
    .height('100%')
  }
}


# 网络权限声明一下可参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/web-component-overview#需要权限

但是仍然不行:就是提示网络无连接:


  09-11 18:13:44.522   26207-26207   C01321/JsRuntime                apppool               W

  [connect_server_manager.cpp:163]not Connected

  09-11 18:13:44.799   26207-26207   C01719/ffrt                    com.foxha...lication  I     6:QueueMonitor:53

  queue monitor ctor leave, watchdog timeout 30000000 us

  09-11 18:13:45.162   26207-26207   C04500/webadapter               com.foxha...lication  E

  [net_connect_adapter_impl.cpp:41] register NetConnCallback failed, ret = 201.

  09-11 18:13:45.162   26207-26207   C04500/chromium                 com.foxha...lication  E

  [network_change_notifier_passive.cc:236] register ohos net connect callback failed.

  09-11 18:13:45.207   26207-26207   C04500/chromium                 com.foxha...lication  I

  [network_change_notifier_passive.cc:164] NetConnCallbackImpl::BindDnsToNetwork, network_for_dns -1

  09-11 18:13:45.214   26207-27124   C04500/chromium                 com.foxha...lication  I

  [network_service.cc:579] Register network context and set network timeout 0 second(s)

  09-11 18:13:45.214   26207-27124   C04500/chromium                 com.foxha...lication  I

  [network_service.cc:1091] bind dns to network return for network is same with -1

  09-11 18:13:45.228   26207-27124   C04500/chromium                 com.foxha...lication  I

  [network_service.cc:579] Register network context and set network timeout 0 second(s)

  09-11 18:13:45.229   26207-27124   C04500/chromium                 com.foxha...lication  I

  [network_service.cc:1073] Network service set network timeout 30 second(s)

  09-11 18:13:45.234   26207-27124   C04500/chromium                 com.foxha...lication  I

  [network_service.cc:579] Register network context and set network timeout 30 second(s)

同时搜索网络,
模拟器无法连接网络,
安装 5.0.0(12 )版本 DevEco Studio 5.0.0 Release 为什么启动的模拟器,没有浏览器应用,且无法加载网络图片资源(网络权限已经开启了),webView也无法正常显示网页(百度),但是都和我的问题无关.

最终方法

突然想到,我的电脑因为安装了VMware虚拟机,所以有多个虚拟网卡,不会deveco Studio尝试使用这个虚拟网卡连接上网吧?
把两个VMware Network Adapter全部禁用,只保留了一个wifi网卡
image.png
重启虚拟机,正常连接
image.png