Home > Article > WeChat Applet > POST request for small program development
There are indeed a lot of pitfalls in the previous post requests. The mini program has been updated since the public beta, so the previous version can only be discarded and written again
There are not many get requests for the mini program I said it, because the documents all have examples of ctrl+c ctrl+v.
1. Add method: "POST"
, case-insensitive
2-1. For ordinary parameter transfer, add 'content-type': "application/x-www-form -urlencoded"
(The content-type here has the same effect as Content-Type. It had to be written in all lowercase before)
2-2. When passing json object parameters, you need to add 'content-type': " application/json"
index.js
var app = getApp() Page({ data: { id: '', username: '', age: '' }, user2json: function() { var that = this; wx.request({ url: 'http://localhost:8080/springMVC/user/bean2json.mn', data: { id: 1, username: "toBeMN", age: 38 }, method: 'POST', header: { "Content-Type": "application/x-www-form-urlencoded" }, success: function(res) { that.setData({ id: res.data.id, username: res.data.username, age: res.data.age }) } }) }, onLoad: function() {} })
index.wxml
<?xml version="1.0" encoding="utf-8"?> <view class="container"> <button bindtap="user2json">bean2json</button> <text>id:{{id}}</text> <text>username:{{username}}</text> <text>age:{{age}}</text> </view>
The above is the detailed content of POST request for small program development. For more information, please follow other related articles on the PHP Chinese website!