鸿蒙模拟器使用localhost地址

        注意,鸿蒙中预览器preview是可以使用localhost:8081这样的本地网络地址的,但是模拟器中却不能使用,需要改成计算机地址,也就是使用ipconfig命令获取到的本机,在本地网络中的IP地址。

ArkTs中:

请求头设置为'content-type': "application/json;charset=utf-8",是为了与服务器的接收数据类型相符合。

public static async getData()
  {
    /*数据初始化*/
    let url="http://localhost:8081/get_liaotian_value";
    let in_post=http.createHttp();
    let response= await in_post.request(
      url,
      {
        method: http.RequestMethod.POST,
        header: { 'content-type': "application/json;charset=utf-8" },
        extraData: {}
      }
    );
    return response.result.toString()
  }

服务器中:

@PostMapping("/get_liaotian_value")
    public ArrayList<Liaotian> get_liaotian_value()
    {
        liaotian=new ArrayList<>();
        System.out.println("请求触达");
        try {
            BufferedReader br=new BufferedReader(new FileReader("D:/liaotian.txt"));
            String l;
            while ((l=br.readLine())!=null)
            {
                String[] c=l.split("&");
                liaotian.add(new Liaotian(c[0],c[1],c[2],c[3]));
            }
            return liaotian;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

 

要利用QEMU实现一个鸿蒙系统模拟器,可以按照以下步骤进行操作: 1. 下载鸿蒙系统镜像文件 在华为官网或者其他可信的下载站点下载鸿蒙系统镜像文件。 2. 安装QEMU 在Linux系统中可以使用以下命令安装QEMU: ``` sudo apt-get install qemu ``` 3. 创建虚拟机 使用以下命令创建一个虚拟机(以鸿蒙系统版本为1.1.0为例): ``` qemu-system-arm -kernel helloworld.bin -M virt -cpu cortex-a15 -m 2048 -nographic ``` 其中,helloworld.bin是鸿蒙系统的镜像文件,-M virt指定了虚拟机使用的是virt机型,-cpu cortex-a15指定了CPU类型,-m 2048指定了虚拟机内存大小,-nographic指定了不使用图形界面。 4. 配置网络 使用以下命令为虚拟机配置网络: ``` qemu-system-arm -kernel helloworld.bin -M virt -cpu cortex-a15 -m 2048 -nographic -netdev user,id=mynet0,hostfwd=tcp::5555-:22 -device virtio-net-device,netdev=mynet0 ``` 其中,-netdev user指定了使用用户模式网络,-id mynet0指定了网络设备的名称,-hostfwd tcp::5555-:22指定了将本地主机的5555端口映射到虚拟机的22端口,-device virtio-net-device,netdev=mynet0指定了虚拟机使用virtio网络设备,并连接到mynet0网络设备。 5. 启动虚拟机 使用以下命令启动虚拟机: ``` qemu-system-arm -kernel helloworld.bin -M virt -cpu cortex-a15 -m 2048 -nographic -netdev user,id=mynet0,hostfwd=tcp::5555-:22 -device virtio-net-device,netdev=mynet0 ``` 启动后,可以使用ssh客户端连接到虚拟机的22端口,即本地主机的5555端口: ``` ssh root@localhost -p 5555 ``` 以上就是利用QEMU实现鸿蒙系统模拟器的基本步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值