
使用 go 自带的 net/http 中的方法请求 url ,总提示too many transfer encodings: ["chunked" "chunked"]导致报错无法获取 Body 内容。 根据关键词找到了相关的issues 在 Golang 的 1.15 版本上才出现的问题,虽说也提供了相关的解决方法(修改 go 的库文件)但是总感觉不方便。 除了 issues 中提到的方法,还有其他方法进行修复吗?
附上返回包的 header
HTTP/1.1 200 OK transfer-encoding: chunked X-Frame-Options: SAMEORIGIN Content-Type: application/json;charset= Transfer-Encoding: chunked Date: Thu, 10 Nov 2022 02:23:46 GMT 1 Mitt 2022-12-03 18:57:59 +08:00 via iPhone 目测是 map 区分大小写导致的,但还得看你怎么调用的,应该给出你调用的例子 |
2 javashell OP @Mitt 代码是这样的 ```go func login() (Token string, Account string, FullName string) { client = &http.Client{} data := "提交的数据" req, _ := http.NewRequest("POST", "http:///xxxxxx", bytes.NewReader([]byte(data))) req.Header.Set("Content-Type", "application/json") req.Header.Set("Accept", "*/*") req.Header.Set("Cache-Control", "no-cache") resp, _ := client.Do(req) r, _ := io.ReadAll(resp.Body) ... ``` |
3 novolunt 2022-12-03 22:46:23 +08:00 |
5 novolunt 2022-12-03 23:19:42 +08:00 |
6 kingcanfish 2022-12-04 10:30:47 +08:00 加个这个请求头试试? ``` req.Header.Set ("Accept-Encoding","identity") ``` |
8 javashell OP @kingcanfish 这个试过了 禁止分片传输没用 |