Directory:

1. Enable plaintext transmission

2. Permission application

3. Introduce the HTTP plug-in

4. Case presentation

5, “Hongmeng OS front-end development guide” collection of articles

Enable plaintext transfer Add the following configuration to the config.json configuration file (if not enabled, do not configure it)

  "deviceConfig": {
     "default": {
       "network": {
         "usesCleartext": true
       }
     }
  },
Copy the code

Add the following permission requests to the module configuration file

 "reqPermissions": [{
      "name":"ohos.permission.INTERNET"
    }],
Copy the code

Introduction ZZR teacher wrote hongmeng HTTP plug-in

Implementation ‘com. Zzrv5. ZZRHTTP: ZZRHTTP: 1.0.1’

Case 1

Mode of use,

New ImageNetWork(" current abilitySlice "," Image build "," Image address ").start();Copy the code

Network pictures

package com.example.shangjinlieren.compontents; import com.zzrv5.mylibrary.ZZRCallBack; import com.zzrv5.mylibrary.ZZRHttp; import com.zzrv5.mylibrary.ZZRResponse; import ohos.aafwk.ability.AbilitySlice; import ohos.agp.components.Image; import ohos.hiviewdfx.HiLog; import ohos.hiviewdfx.HiLogLabel; import ohos.media.image.ImageSource; import ohos.media.image.PixelMap; public class ImageNetWork { private final static HiLogLabel LABEL_LOG = new HiLogLabel(HiLog.LOG_APP, 0, "HmOSImageLoader"); private AbilitySlice abilitySlice; private Image image; private String url; public ImageNetWork(AbilitySlice abilitySlice, Image image, String url) { this.abilitySlice = abilitySlice; this.image = image; this.url = url; } public void start() { ZZRHttp.get(url, new ZZRCallBack.CallBackString() { @Override public void onFailure(int code, String errorMessage) {// HTTP access error, this part of the work in the main thread; // The UI can be updated. Please do not block. System.out.println("errorMessage"+errorMessage); } @override public String onParseResponse(ZZRResponse response) {ImageSource ImageSource = ImageSource.create(response.inputStream, null); / / source according to the pictures to create bitmap PixelMap PixelMap = imageSource. CreatePixelmap (null); / / need to asynchronous rendering UI abilitySlice getUITaskDispatcher () asyncDispatch (new Runnable () {@ Override public void the run () {/ / display to the component System.out.println(" mount "); image.setPixelMap(pixelMap); pixelMap.release(); }}); return super.onParseResponse(response); } @Override public void onResponse(String response) { } }); }}Copy the code

Author: BLUESKYHOST

For more information, visit Harmonyos.51cto.com, a collaboration between 51CTO and Huawei