#鸿蒙通关秘籍#如何在鸿蒙应用开发中实现GET和POST请求?

HarmonyOS
2024-11-29 15:32:22
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
时光旅人NoSQL

通过封装的h_request库,可以轻松实现GET和POST请求:

  1. 使用GET请求:
http.get('/swiperdata').then((res) => {
  console.log(res.data);
}).catch((error) => {
  console.error(error);
});
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  1. 使用POST请求:
http.post('/hotmovie', { start: 0, count: 1, city: "郑州" }).then((res) => {
  console.log(res.data);
}).catch((error) => {
  console.error(error);
});
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  1. GET请求带参数:
http.get('api/v1/musicsearchlrc', { params: { id: "543656129", kind: "wy" } }).then((res) => {
  console.log(res.data);
}).catch((error) => {
  console.error(error);
});
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
分享
微博
QQ
微信
回复
2024-11-29 16:58:12


相关问题
HarmonyOS RCP GET请求POST请求如何传参
680浏览 • 1回复 待解决