微信小程序 wx.request 出现 Failed to load resource: the server responded with a status of 400

来源:互联网 发布:Linux 子系统 编辑:程序博客网 时间:2024/05/16 15:01

首先说遇到的问题

index.js

[javascript] view plain copy
  1. var API_URL = 'https://api.douban.com/v2/movie/top250';  
  2. Page({  
  3.   data: {  
  4.     movies: []  
  5.   },  
  6.   onLoad: function () {  
  7.     wx.showToast({  
  8.       title: "加载中",  
  9.       icon: "loading",  
  10.       duration: 10000  
  11.     });  
  12.     wx.request({  
  13.       url: 'https://api.douban.com/v2/movie/top250',  
  14.       data: {},  
  15.       header: {  
  16.         'Content-Type''application/json'  
  17.       }, // 设置请求的 header  
  18.       success: function (res) {  
  19.         // success  
  20.         console.log(res);  
  21.       }  
  22.     });  
  23.   }  
  24.   
  25. })  

后来把request中的header改成 'application/x-www-form-urlencode'  之后,就没有问题了

阅读全文
0 0