小程序请求不了豆瓣接口api

  通过豆瓣api可以获取很多电影、书籍等的数据信息。昨晚上用微信小程序请求豆瓣api,竟然被豆瓣拒绝了。(豆瓣设置了小程序的访问权限)。出现403报错;如下图:

image.png

由于原因是豆瓣那边设置了对小程序的访问权限,后来我也查了资料,很多人都遇到这种问题;如果你没有配置nginx或者apache环境的话,配置一个,我这边是配置nginx环境,在nginx.conf加入以下配置:

image.png

代码:

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/; }

重启nginx:

修改小程序那边的请求路径为

http://localhost/v2/movie/top250

,结果如下图:

image.png

群主个人博客:http://www.dongdang.xin/

推荐文章:php容联云通讯,发送短信微信H5支付

猜你喜欢

转载自blog.csdn.net/weixin_39801446/article/details/81041368