-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v3版本请求数据后台接收到的是单个字母的数组 #1218
Comments
content-type改成application/json一切正常 |
写了一段最简单的代码测试,并没有出现你说的情况,可以问问你们后端有没有做其他处理 |
用的是thinkphp5.1 |
抓包看一下吧,看看App端往服务端传的时候是什么样的 |
漏看了你的代码,你是自己给转成字符串了。确实有问题,近期会发版修复 |
Wangyaqi
added a commit
that referenced
this issue
Jan 8, 2020
2.5.5 alpha 已修复 |
zhetengbiji
added a commit
that referenced
this issue
Jan 13, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题描述
v3版本请求数据后台接收到的是单个字母的数组
复现步骤
[复现问题的步骤]
post('user/signin', {
username,
password,
type,
captcha
})
options.url = url
options.data = data
options.method = 'POST'
options.data = serialize(options.data) //uni.request自带的转换query不支持复杂对象所以自己实现了个
return this.request(options)
function serialize (obj, prefix) {
const str = []
let p
if (obj.length === 0) {
// str.push(encodeURIComponent(prefix) + '=1')
} else {
for (p in obj) {
if (obj.hasOwnProperty(p)) {
const k = prefix ? prefix + '[' + p + ']' : p
let v = obj[p]
if (v instanceof Date) {
v = parseTime(v)
}
str.push((v !== null && typeof v === 'object') ? serialize(v, k) : encodeURIComponent(k) + '=' + encodeURIComponent(
v))
}
}
}
return str.join('&')
}
预期结果
应该跟h5的request一样,后台可以正常接收参数
实际结果
array (
0 => 'u',
1 => 's',
2 => 'e',
3 => 'r',
4 => 'n',
5 => 'a',
6 => 'm',
...
)
本来是 username=...
非v3版本可以
系统信息:
补充信息
给uni.request传递的config为
{
baseUrl: "http://xxx.xxx.x.xxx/api/"
complete: ƒ (response)
data: "username=xxx&password=xxx&type=xxx&captcha="
dataType: "json"
fail: ƒ fail()
header: {content-type: "application/x-www-form-urlencoded", X-AUTH-DEVICE: ""}
method: "POST"
responseType: "text"
silence: false
success: ƒ success()
url: "http://xxx.xxx.x.xxx/api/user/signin"
}
The text was updated successfully, but these errors were encountered: