您的位置:首页 > 产品设计 > UI/UE

微信小程序解决请求: 400 (Bad Request)错误

2017-03-29 16:18 871 查看

网络请求



从微信开放平台上,我们可以看到网络请求是这样的,然后就去尝试一下,看看到底行不行!

Page({
data: {
motto: 'Hello World',
imageUrl:"url",
list:[]
},onLoad: function(){
const mThis=this;
wx.request({
url: 'https://api.douban.com/v2/movie/in_theaters',
data: {},
header:{
"Content-Type": "application/json"
},
success: function(res) {

console.log(res.data);
mThis.setData({
list:res.data.subjects
})
}
});
}
})


得到的调试结果:



在界面中也看不到我们设置的图片



正确写法

//我们需要把request里的header修改一下:
header:{
// "Content-Type":"application/json"
//这里修改json为text   json的话请求会返回400(bad request)
"Content-Type": "application/text"
},


现在再来看一下,调试的界面:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  微信 小程序 400
相关文章推荐