后台接口的连接
1、数据传递post
主要声明数据类型 ‘content-type’: ‘application/json’
Component({
methods: {
compare(e){
wx.request({
method:'POST',
url: 'http://ip:端口/cs/getProductInfo',
data:{'code':'12'},
header: {
'content-type': 'application/json'
},
success:function(res){
console.log(res)
}
})
},
}
})
2、后台
@RequestMapping("/getProductInfo")
public void getProductInfo(HttpServletRequest request,@RequestBody Map<String,String> param) throws Exception {
//数据在param中
}
3、数据获取
Component({
methods: {
compareb(e){
// 发起GET请求
wx.request({
url: 'http://192.168.1.47:90/cs/yangshiheibai',
success: function (res) {
console.log(res.data);
},
fail: function (error) {
console.error('请求失败', error);
}
});
}
}
})