三方件@ohos/axios中发起post请求,如何以queryParams形式传递参数

三方件@ohos/axios中发起post请求,如何以queryParams形式传递参数

HarmonyOS
2024-03-18 22:55:38
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
hflame
  • 方式一:使用axios.post接口只接收一个参数,Url.URLParams需要转成字符串拼接在url后面。
let params:Url.URLParams = new Url.URLParams() 
params.append("fod" : '1') 
params.append("bard" : '2') 
axios.post('https://developer.mozilla.org/?' + params.toString()).then(res => { 
  this.message = "request result: " + JSON.stringify(res.data); 
}).catch(err => { 
  this.message = "request error: " + err.message; 
})
  • 方式二:使用axios接口只接收一个config对象,请求参数写在config对象的params中。
axios({ 
  url: 'https://developer.mozilla.org/?', 
  method: 'post', 
  params: { 
    fod: '1', 
    bard: '2', 
  } 
}).then(res => { 
  this.message = "request result: " + JSON.stringify(res.data); 
}).catch(err => { 
  this.message = "request error: " + err.message; 
})

参考链接

Url.URLParams

分享
微博
QQ
微信
回复
2024-03-19 22:42:47
相关问题
http请求如何以表单形式进行传输
444浏览 • 1回复 待解决
http请求如何以JSON形式进行传输
323浏览 • 1回复 待解决
HTTP GET请求如何传递参数
1360浏览 • 1回复 待解决
如何获取可用的三方
227浏览 • 1回复 待解决
开发第三方SDK如何编译?
11706浏览 • 2回复 待解决
三方应用如何获取蓝牙mac地址
394浏览 • 1回复 待解决
三方应用如何获取http代理信息
202浏览 • 1回复 待解决
HarmonyOS如何移植第三方MCU?
7147浏览 • 1回复 待解决
Native工程中如何使用其他三方so库
340浏览 • 1回复 待解决
在Native侧如何集成三方SO库
251浏览 • 1回复 待解决
求大佬告知如何使用三方cpp库
213浏览 • 1回复 待解决
有谁知道如何引入三方so
538浏览 • 1回复 待解决
三方怎么装鸿蒙系统?
594浏览 • 1回复 待解决
关于JS http请求参数传递问题
5563浏览 • 2回复 待解决
OHPM包管理怎么安装第三方
2116浏览 • 1回复 待解决
ArkTS API 9 Stage 如何引用第三方字体?
1498浏览 • 1回复 待解决