HarmonyOS http请求流数据报错?

使用http.HttpRequest中的requestInStream方法读取数据报错

requestInStream error = 2300023:Failed writing received data to disk/application

阅读 581
1 个回答

参考示例:

import http from '@ohos.net.http';
import fs from '@ohos.file.fs';

export async function testHttp2() {
  let httpRequest = http.createHttp();
  let filePath = getContext().filesDir + "test" + Date.now().toString() + ".mp4";
  let stream = fs.createStreamSync(filePath, "r+");
  let url3 =
    "https://xxx.mp4";
  httpRequest.requestInStream(url3, {}, (err, data) => {
    if (err) {
      console.log("error is" + JSON.stringify(err));
      httpRequest.destroy();
      return;
    } else {
      console.log("respcode iS :" + data);
    }
  })
  httpRequest.on("dataReceive", (data) => {
    console.info("data len is " + data.byteLength);
    stream.write(data);
  })

  httpRequest.on("dataEnd", () => {
    stream.flush();
    httpRequest.destroy();
    console.log("data receive end");
  })
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进