HarmonyOS 关于rcp请求封装问题

我这边封装了rcp请求的一个公共方法返回如下

export async function commonRequest(){
  return request.post().then(async (response : rcp.Response) => {}).catch((err: BusinessError) => {})
}
  • 1.
  • 2.
  • 3.

在外面使用这个方法时候,then方法的response解析不出来undefined,如何传递呢

export function keyExchangeRequest() {
  let paramDict = new HashMap<string, string>()
  return commonRequest(RequestKeyID.RequestKeyGen, '504', '504', paramDict).then((response) => {
    console.info(`keyExchangeRequest Response succeeded: ${response}`);
  }).catch((err: BusinessError) => {
    console.error(`Err: Code is ${err.code}, message is ${err.message}`);
  });

}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
HarmonyOS
2024-12-19 17:09:00
647浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

rcp封装请参考以下示例:

export function commonRequest() {
  const session = rcp.createSession();
  let content1 = "data to send";
  const content: rcp.RequestContent = {
    "name": "张三"
  }
  return session.post("https://www.huawei.com", content1)
}

调用:
commonRequest().then((response) => {
  console.log("test---------" + response.toString());
}).catch((err: BusinessError) => {
  console.error("err:");
});
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
分享
微博
QQ
微信
回复
2024-12-19 19:20:35


相关问题
HarmonyOS 关于rcp.createSession封装
628浏览 • 1回复 待解决
HarmonyOS rcp通用请求的Promise封装
1078浏览 • 1回复 待解决
HarmonyOS rcp请求问题
875浏览 • 1回复 待解决
HarmonyOS 关于页面架构封装问题
670浏览 • 1回复 待解决
HarmonyOS rcp取消网络请求
1026浏览 • 1回复 待解决
HarmonyOS http请求封装
891浏览 • 1回复 待解决
HarmonyOS rcp网络请求报错1007900994
968浏览 • 1回复 待解决
HarmonyOS rcp请求如何传递参数
818浏览 • 1回复 待解决
HarmonyOS rcp请求拦截器
1499浏览 • 1回复 待解决
HarmonyOS RCP GET请求、POST请求如何传参
1038浏览 • 1回复 待解决
HarmonyOS rcp网络请求证书配置
932浏览 • 1回复 待解决
rcp模块能力发起post请求
2218浏览 • 1回复 待解决
HarmonyOS http请求封装
936浏览 • 1回复 待解决
HarmonyOS RCP网络请求对Cache的支持
990浏览 • 1回复 待解决
HarmonyOS rcp网络请求返回数据为null
976浏览 • 1回复 待解决
HarmonyOS rcp如何进行fetch流式请求
812浏览 • 1回复 待解决
使用rcp模块能力发送Get请求
2052浏览 • 1回复 待解决
关于JS http请求参数的传递问题
8409浏览 • 2回复 待解决