uni-app进行http后台服务请求,一般使用request。
官方解释:https://uniapp.dcloud.io/api/request/request
一、基本用法
uni.request({
url: 'http://localhost/myUniApp/php/login.php', //仅为示例,并非真实接口地址。
data: {//参数
rawData: rawData,
code: loginRes.code
},
header: {
'content-type': 'hello' //自定义请求头信息
"token":"hfhdsjkfhsdjkfhsjkdf",
},
method:'POST'//请求方式 或GET,必须为大写
success: res => {
console.log('返回', res.data);
}
}),
fail:res =>{
//失败时候回调
}
二、使用request发送formData格式请求
对于formdata格式的请求,只需要在header中修改content-type类型为application/x-www-form-urlencoded即可。
header: {
'content-type': 'application/x-www-form-urlencoded'
}
修改后: