HarmonyOS 使用http接口获取图片流result为空?

返回响应体

{"responseCode":200,"cookies":"","header":{"content-length":"1744","content-type":"application/json; charset=utf-8","date":"Wed, 06 Mar 2024 08:26:49 GMT","server":"nginx"},"result":{},"resultType":2,"performanceTiming":{"dnsTiming":0.159,"firstReceiveTiming":1301.064,"firstSendTiming":0.409,"redirectTiming":0,"responseBodyTiming":1302.414,"responseHeaderTiming":1302.405,"tcpTiming":0,"tlsTiming":0,"totalFinishTiming":1301.302,"totalTiming":1303.02}}
http.createHttp().request(
  `https://preapps.eshiyun.info/account/image/getCode?uuid=${this.generateRandomNumber(32)}`,
  {
    expectDataType: http.HttpDataType.ARRAY_BUFFER,
    method: http.RequestMethod.GET,
    header: {
      // 在每个请求前添加自定义头部信息
      'User-Agent': 'OS/Android:14 smyapp/standardsmy Brand/Xiaomi:2211133C Display/1080*2252 standardsmy/2.7.5.02',
      'eshimin-version': '2.7.5.02',
      'system-version': '14',
      'nonce': randomChar,
      'timeStamp': currentTime.toString(),
      'sign': sign,
      'uri': '/account/image/getCode',
      'hversion': '2.1',
      'tgt': tgt,
      'token': tgt
    }
  }
阅读 506
1 个回答

可以在回调方法内通过 ArrayBuffer 参数接收,再打印字节长度来判断响应内容是否为空,如

let imageData: ArrayBuffer = data.result as ArrayBuffer;
console.info("data length:" + imageData.byteLength);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
logo
HarmonyOS
子站问答
访问
宣传栏