Skip to content
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

Closed
he426100 opened this issue Jan 4, 2020 · 7 comments
Closed

v3版本请求数据后台接收到的是单个字母的数组 #1218

he426100 opened this issue Jan 4, 2020 · 7 comments

Comments

@he426100
Copy link

he426100 commented Jan 4, 2020

问题描述
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版本可以

系统信息:

  • 发行平台: 5+ App
  • 操作系统 Android 6.0.1
  • HBuilderX版本 2.5.1
  • uni-app版本 编译器版本:2.5.1(v3)
  • 设备信息 mumu模拟器

补充信息
给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"
}

@he426100
Copy link
Author

he426100 commented Jan 4, 2020

content-type改成application/json一切正常

@Wangyaqi
Copy link
Contributor

Wangyaqi commented Jan 7, 2020

echo json_encode(array(status=>0,post=>$_POST,get=>$_GET,requestBody=>file_get_contents('php://input')));

写了一段最简单的代码测试,并没有出现你说的情况,可以问问你们后端有没有做其他处理

@he426100 he426100 closed this as completed Jan 7, 2020
@he426100 he426100 reopened this Jan 7, 2020
@he426100
Copy link
Author

he426100 commented Jan 7, 2020

用的是thinkphp5.1

@Wangyaqi
Copy link
Contributor

Wangyaqi commented Jan 7, 2020

抓包看一下吧,看看App端往服务端传的时候是什么样的

@he426100
Copy link
Author

he426100 commented Jan 8, 2020

U0HL8CEMEQ9R EY@24LBPUB
抓包出来就是发送的数组(抓包工具:mitmproxy)

console.log(request.config.data) => nickname=%E5%91%B5%E5%91%B51
在v3版本下content-type 为 application/x-www-form-urlencoded会这样,application/json不会,非v3不会

@Wangyaqi
Copy link
Contributor

Wangyaqi commented Jan 8, 2020

漏看了你的代码,你是自己给转成字符串了。确实有问题,近期会发版修复

@zhetengbiji
Copy link
Collaborator

2.5.5 alpha 已修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants