【go】go web 参数获取错误
go iris web 框架,同时有两个请求到达go的时候,参数会有上次请求的部分参数。最后导致json序列化时失败
readObjectStart: expect { or n, but found , error found in #0 byte of ...||..., bigger context ...||...
场景重现:
1、登录
在go语言的net/http/server.go
源码 1822行func (c *conn) serve(ctx context.Context) {}
函数debug,
c.bufr.buf
的值是:
POST /auth/login HTTP/1.1Host: 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个请求reload
和page
,其中reload
请求不带参数,page
携带参数:
但是在net/http/server.go
源码 1822行func (c *conn) serve(ctx context.Context) {}
函数断点是发现参数异常:
POST /subject/page HTTP/1.1Host: 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序列化失败,请问下这个问题怎么解决,原因是什么?
每次请求参数前,请进行初始化操作
这个是前端问题吧.你说的多次请求,每次请求都带有前面请求的一部分参数这就是个问题啊,解决这个问题就好了啊
回答
以上是 【go】go web 参数获取错误 的全部内容, 来源链接: utcz.com/a/110933.html