使用rcp模块能力发送Get请求

使用rcp模块能力发送Get请求

HarmonyOS
2024-05-28 20:39:17
1752浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
是潘达不是胖达

本模块提供HTTP数据请求功能。应用程序可通过HTTP发起数据请求。常见的HTTP方法包括GET、POST、HEAD、PUT、DELETE、PATCH、OPTIONS。

使用模块功能实现GET请求发送

使用的核心API

@rcp.Session.Get

核心代码解释

Http_GetRcp() { 
  const session = rcp.createSession(); 
  session.get("https://www.baidu.com").then((response) => { 
    console.log("test---------" + response.toString()); 
    AlertDialog.show( 
      { 
        title: 'request接口回调结果', 
        message: '请求网站:' + '百度' + '\n\n' + 'Callback Data: ' + response.toString(), 
      }) 
  }).catch((err:BusinessError)=> { 
    AlertDialog.show( 
      { 
        title: 'request接口回调结果', 
        message: '请求失败,错误信息:' + err.data, 
      }) 
    console.error("test err:" + JSON.stringify(err)); 
  }); 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.

注明适配的版本信息

IDE版本:4.1.3.500

SDK版本:HarmonyOS Next Developer Preview 1

分享
微博
QQ
微信
回复
2024-05-29 21:44:02


相关问题
rcp模块能力发起post请求
1915浏览 • 1回复 待解决
HarmonyOS RCP GET请求、POST请求如何传参
739浏览 • 1回复 待解决
HarmonyOS rcp模块使用例子
321浏览 • 1回复 待解决
使用componentSnapshot.get能力报错
1102浏览 • 1回复 待解决
网络请求-GET请求传参
1175浏览 • 1回复 待解决
HarmonyOS rcp能力调用demo
341浏览 • 1回复 待解决
HarmonyOS rcp请求问题
575浏览 • 1回复 待解决
HarmonyOS rcp取消网络请求
689浏览 • 1回复 待解决
Js 荣耀手机get请求失败
5570浏览 • 1回复 待解决