How to solve the problem of request 400 in WeChat applet

一个新手
Release: 2018-05-10 16:58:02
Original
8623 people have browsed it

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)...)
    Copy after login

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);
      }
    });
Copy after login

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'
      },
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!