Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Golang错误的http重新请求头_Go_Http Headers_Go Gin - Fatal编程技术网

Golang错误的http重新请求头

Golang错误的http重新请求头,go,http-headers,go-gin,Go,Http Headers,Go Gin,我正在构建2个API。一个人向另一个人提出请求 要调用接收请求的api,我们需要传递一个X-Token头。我在和Golang一起做这件事 client := &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, }, } req, err := http

我正在构建2个API。一个人向另一个人提出请求

要调用接收请求的api,我们需要传递一个X-Token头。我在和Golang一起做这件事

client := &http.Client{
    Transport: &http.Transport{
        TLSClientConfig: &tls.Config{
            InsecureSkipVerify: true,
        },
    },
}

req, err := http.NewRequest("GET", "https://localhost:8086/v2/example", nil)
if err != nil {
    c.JSON(http.StatusInternalServerError, gin.H{"Error": err.Error()})
}
req.Header.Add("accept", "application/json")
req.Header.Add("content-type", "application/json")
req.Header.Add("x-token", "a2e63ee01401aaeca78be023dfbb8c59")

resp, err := client.Do(req)
在另一个API中,我得到如下http头:

token:=c.Request.Header.Get(“x-token”)

我不知道为什么我的头带有另一个值而没有X标记。谢谢

fmt.Printf的结果(“%+v”,c.Request.Header)

我不知道我的x-token、accept和content-type头在哪里

重要

  • 如果我在Postman上使用x-token头向请求的API发出请求,我会得到正确的头
  • 如果我更改发出请求的API上的请求地址,例如,我也会得到正确的头

  • 你好,伙计们!我找到了解决办法

    我还不知道为什么。。。但我认为golang不处理任何尾随斜杠url



    那是我的问题

    我只是复制并通过golang生成的邮递员代码。。。这就是最大的区别


    谢谢Postman先生…

    fmt.Println(c.Request.Header)的输出是什么?@Apin我编辑了这个问题!:)
    map[User-Agent:[Go-http-client/1.1] Referer:[https://localhost:8086/v2/example] Accept-Encoding:[gzip]]