HarmonyOS http中dataReceive、dataReceiveProgress两个事件监听未回调?

如题:HarmonyOS http中dataReceive、dataReceiveProgress两个事件监听未回调?

阅读 708
1 个回答
static get() {
  const uri = "https://gitee.com/static/images/logo-black.svg?t=158106664";
  try {
    const req = http.createHttp();
    req.on('headersReceive', (headers: Object) => {
      console.info(tag + 'headersReceive: ' + JSON.stringify(headers));
    })
    req.on('dataReceive', (data: ArrayBuffer) => {
      console.info(tag + 'dataReceive: ' + JSON.stringify(data));
    })
    req.on('dataReceiveProgress', (data: http.DataReceiveProgressInfo) => {
      console.info(tag + 'dataReceiveProgress: ' + JSON.stringify(data));
    })
    req.requestInStream(uri)
      .then((data: number) => {
        console.info(tag + 'request success, resp: ' + JSON.stringify(data));
        req.destroy();
        console.info(tag + 'request destroy');
      })
      .catch((err: BusinessError) => {
        console.info(tag + 'request failed, err: ' + JSON.stringify(err));
      })
  } catch (err) {
    console.log(tag + 'httpRequest_get err : ' + JSON.stringify(err));
  }
}

使用 req.requestInStream

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-http-V5\#requestinstream10

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进