Home  >  Article  >  WeChat Applet  >  How to solve the problem of request 400 in WeChat applet

How to solve the problem of request 400 in WeChat applet

一个新手
一个新手Original
2018-05-10 16:58:028670browse

WeChat API

  • 对于header['content-type'] 为application/json 的数据,会对数据进行json序列化
    对于header['content-type'] 为 application/x-www-form-urlencoded 的数据,会哦将数据转换成query string (encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...)

Listing code

The following is my WeChat account List of codes in the program

//请求URL
    wx.request({
      url:"https://api.douban.com/v2/movie/top250",      data:{},      header: {      'content-type': 'application/json' // 默认值
      },
      success:function(res){
        wx.hideToast();
        console.log(res.data);
      }
    });

Compilation error

The following are the errors that occur after compilation

How to solve the problem of request 400 in WeChat applet

Solving the problem

I modified the header in the request as follows:

 header: {        //'content-type': 'application/json' // 默认值
        //这里修改json为text   json的话请求时会返回400(bad request)
        'content-type': 'application/texts'
      },

After modification, debugging is as follows

How to solve the problem of request 400 in WeChat applet

The above is the detailed content of How to solve the problem of request 400 in WeChat applet. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn