之前的post的请求确实有不少的坑,公测以来小程序一直在更新,所以之前的版本只能作废掉,重新写一次
对于小程序的get请求就不多说了,因为文档都有例子ctrl+c ctrl+v就好了
1.加上 method: "POST",不区分大小写
2-1.普通参数传递需加上'content-type': "application/x-www-form-urlencoded"(这里的content-type跟Content-Type现在效果一样,之前得写成全小写)
2-2.json对象参数传递需加上'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>以上就是小程序开发之POST请求的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号