Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
762 views
in Technique[技术] by (71.8m points)

go web 参数获取错误

go iris web 框架,同时有两个请求到达go的时候,参数会有上次请求的部分参数。最后导致json序列化时失败

readObjectStart: expect { or n, but found  , error found in #0 byte of ...||..., bigger context ...||...

场景重现:

1、登录login.png

在go语言的net/http/server.go源码 1822行func (c *conn) serve(ctx context.Context) {}函数debug,

2.png
3.png
c.bufr.buf的值是:
4.png

POST /auth/login HTTP/1.1
Host: localhost:9000
Connection: keep-alive
Content-Length: 405
Accept: application/json, text/plain, */*
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
Content-Type: application/json;charset=UTF-8
Sec-Fetch-Site: same-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://localhost:8080/auth
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9

{"a1":"zmKK5HMForFJiasoLrzbWfIudvCxgKeWooRtJdpBNmc6ywy93VSJOLTtHWond3Y2QUamqylOOQ5kKlgytXDjV29b1J82UAsZs3Me0upq4mHJrmcGyqPsjMKrLe5ESbP7ex2/yumZyYjA184NCeBtegQ6FRuOtWtsnLvPrxeVhek=","a2":"ZsCPD7Oq4r50jKIRX9Zr8y64P5DJpxLw0MOM43UjhiFPCB4FvWCUYO76kdrxJKMhOXyHKlChxoR/5iIn+YhxtB8eYKvE7qtKFVmyu6mZ7uKm4svehRTLBaCQBKxJ9H9bICwQncpW7B9mvvJyQKBXX17/yWTDT61xwxPSsGUSNXw=","a3":"c9f45a8b-9b54-44bb-81be-a6af87b1c28f"}                                                                                                                   

这里的参数获取是OK的,登录也是成功的。

2,登录后同时发起了2个请求reloadpage,其中reload请求不带参数,page携带参数:
5.png

但是在net/http/server.go源码 1822行func (c *conn) serve(ctx context.Context) {}函数断点是发现参数异常:

6.png

POST /subject/page HTTP/1.1
Host: localhost:9000
Connection: keep-alive
Content-Length: 21
Accept: application/json, text/plain, */*
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ1c2VyIiwiZXhwIjoxNTg5MDg4NTM2LCJqdGkiOiIxMjM1ODA2ODIyNDM1MTMxMzkyIiwiaWF0IjoxNTg5MDg3NjM2LCJpc3MiOiJxeHVuIiwibmJmIjoxNTg5MDg2NzM2LCJzdWIiOiJ1c2VyLXByb2ZpbGUifQ.sy1wg-C1vNkTT_R5dpjUZPUqY_YBmZ4ICbR0gCEvM8w
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
Content-Type: application/json;charset=UTF-8
Sec-Fetch-Site: same-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://localhost:8080/home/subject
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9

{"limit":10,"page":1}ehRTLBaCQBKxJ9H9bICwQncpW7B9mvvJyQKBXX17/yWTDT61xwxPSsGUSNXw=","a3":"c9f45a8b-9b54-44bb-81be-a6af87b1c28f"}   

其中的参数竟然有部分以前的请求参数混入其中。导致json序列化失败,请问下这个问题怎么解决,原因是什么?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

每次请求参数前,请进行初始化操作


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...