在使用網絡請求時,發現根據微信官方的API的方法進行操作出現Invalid request 400錯誤,到底怎麼回事呢?
以下是程序代碼:
/**
* 加載電影
*/
loadMovie:function(){
var page = this;
wx.request({
url: 'https://api.douban.com/v2/movie/in_theaters',
header:{
'Content-Type':"application/json"
},
success:function(res){
var subjects = res.data.subjects;
processSubjects(subjects);
page.setData({ movies: subjects, hidden:true});
}
})
},
經過一般搜索研究發現,微信開發者工具在更新到最新版本後,相應的參數配置也發生了變化,官網給出的這個配置已經不能用了, 'content-type': 'application/json' 需要改爲'content-type':'application/text'
以上代碼經過修改調整後,如下代碼所示:
/**
* 加載電影
*/
loadMovie:function(){
var page = this;
wx.request({
url: 'https://api.douban.com/v2/movie/in_theaters',
header:{
'content-type':'application/text'
},
success:function(res){
var subjects = res.data.subjects;
page.processSubjects(subjects);
page.setData({ movies: subjects, hidden:true});
}
})
},