|
通过豆瓣api可以获取很多电影、书籍等的数据信息。昨晚上用微信小程序请求豆瓣api,竟然被豆瓣拒绝了。(豆瓣设置了小程序的访问权限)。
onLoad: function (options) {
this.getMoviesData('https://api.douban.com/v2/book/1220562')
},
getMoviesData:function(url){
wx.request({
url: url,
data: {},
method: 'GET',
header: { 'content-type': 'application/json' },
success: function (res) {
console.log(res)
},
fail: function () {
console.log('fail')
},
})
}
location /v2/ {
proxy_store off;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Referer 'no-referrer-when-downgrade';
proxy_set_header User-Agent 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36';
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_pass https://api.douban.com/v2/;
}
onLoad: function (options) {
this.getMoviesData('http://localhost/v2/book/1220562')
},
getMoviesData:function(url){
wx.request({
url: url,
data: {},
method: 'GET',
header: { 'content-type': 'application/json' },
success: function (res) {
console.log(res)
},
fail: function () {
console.log('fail')
},
})
}
竟然还是错误!!!
onLoad: function (options) {
this.getMoviesData('http://localhost/v2/book/1220562')
},
getMoviesData:function(url){
wx.request({
url: url,
data: {},
method: 'GET',
header: { 'content-type': 'application/xml' },
success: function (res) {
console.log(res)
},
fail: function () {
console.log('fail')
},
})
}
|