The Go Programming Language
› http://golang.org/
› Go Playground
Go Projects
› Revel Web Framework
javashell

Golang http 请求提示重复的 header 头如何解决?

  •  
  •   javashell · Dec 3, 2022 · 3139 views
    This topic created in 1431 days ago, the information mentioned may be changed or developed.

    使用 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=UTF-8
    Transfer-Encoding: chunked
    Date: Thu, 10 Nov 2022 02:23:46 GMT
    
    8 replies  •  2022-12-04 12:13:55 +08:00
    Mitt
    Mitt
    Dec 3, 2022 via iPhone
    1
    目测是 map 区分大小写导致的,但还得看你怎么调用的,应该给出你调用的例子
    javashell
    javashell
    OP
    Dec 3, 2022
    2
    @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)

    ...
    ```
    novolunt
    novolunt
    Dec 3, 2022
    3
    以下是人工智障的回答
    Vintingb
    Vintingb
    Dec 3, 2022 via iPhone
    4
    @novolunt 这是啥网站
    kingcanfish
    kingcanfish
    Dec 4, 2022
    6
    加个这个请求头试试?
    ```
    req.Header.Set ("Accept-Encoding","identity")
    ```
    alsas
    alsas
    Dec 4, 2022
    7
    @novolunt 禁止中国号码注册 咋办
    javashell
    javashell
    OP
    Dec 4, 2022
    8
    @kingcanfish 这个试过了 禁止分片传输没用
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1365 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 22:16 · PVG 06:16 · LAX 14:16 · JFK 17:16
    ♥ Do have faith in what you're doing.