小程式不能呼叫豆瓣API介面(403錯誤碼)
阿新 • • 發佈:2018-12-09
1、按照網上較為流行的豆瓣API呼叫方法一般如下
onLoad: function(options) {
wx.request({
url:"https://api.douban.com/v2/movie/top250",
data: {},
method: 'GET',
header: {
"Content-Type": "application"
},
success:function(res){
console.log(res.data)
}
})
},
但是這樣寫會返回403錯誤
2、這個問題困擾了比較長時間,後來在網上查詢了一下,解決方法為:
onLoad: function(options) { wx.request({ url:"http://t.yushu.im//v2/movie/top250",//url更改為此地址 data: {}, method: 'GET', header: { "Content-Type": "application" }, success:function(res){ console.log(res.data) } }) },
獲取資料成功。
3、如果出現“不在request合法域名列表”的錯誤
記得勾選
、
或者在小程式的開發者設定裡將https:t.yushu.im新增進request域名。