今天在做一个微信小程序的时候,用到豆瓣API v2 一直400 badrequest,
代码如下
const api = require('../../utils/api.js')
Page({
data:{
movies:[],
hidden:false
},
onLoad:function(){
// this.getMovies("30")
wx.request({
url:"https://api.douban.com/v2/movie/coming_soon",
method:"GET",
success:function(res){
console.log(res)
}
})
},
// getMovies:function(num){
// let url = api.searchMovies +`?count=${num}`,
// self = this;
// wx.request({
// url:url,
// method:"GET",
// success:function(res){
// let data = res.subjects
// console.log(data)
// self.setData({
// hidden:true,
// movies:data
// })
// }
// })
// }
})
尝试换了好多个接口地址都报400,然而我用浏览器就可以成功拿到数据了,折腾一下午不知道为什么不行...

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
可能是豆瓣方面对接口的请求来源做了限制,可以从 UA 方面排查一下,用微信小程序的 UA 发起一个请求试试
微信允许小程序跨域并不意味着豆瓣允许明显不正常的 UA 获取资源
你要在公众平台上设置可请求的域名啊
header:{
},
这样做ide能请求成功,在手机里又不行了,报400的错误