微信小程序访问豆瓣电影api400错误解决方法

时间:2023-03-09 18:43:46
微信小程序访问豆瓣电影api400错误解决方法

最近在跟着demo学习微信小程序,却卡在了第一步请求豆瓣电影api上,折腾了很久,代码如下:

wx.request({
url : "https://api.douban.com/v2/movie/in_theaters",
data: {},
header:{
"Content-Type":"application/json"
},
success: function(res) {
console.log(res.data);
var data = res.data;
currentPage.setData({
list : data.subjects
})
},
});

微信小程序访问豆瓣电影api400错误解决方法

原来是开发工具升级后,请求的header的Content-type写法变了(我现在使用的开发工具版本为0.11),需要改为

header:{
"Content-Type":"json"
},

这样就可以正常请求了