tiagopotencia
tiagopotencia

Reputation: 25

Golang wrong http resquest header

I'm building 2 apis. One make request to another.

To call the api that receives requests, we need to pass a X-Token Header. I'm doing this with 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)

In the other API, i get the http header with gin like this:

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

I dont know why my header arrives with another value and no X-Token. Thanks!

Result of fmt.Printf("%+v", c.Request.Header):

map[User-Agent:[Go-http-client/1.1] Referer:[https://localhost:8086/v2/example] Accept-Encoding:[gzip]]

I don't know where is my x-token, accept and content-type headers....

IMPORTANT

Upvotes: 1

Views: 1116

Answers (1)

tiagopotencia
tiagopotencia

Reputation: 25

Helo, guys! i found the solution....

I don't know why yet... but i think golang don't handle no trailing slash url's....

https://localhost:8086/v2/example
is different of
https://localhost:8086/v2/example/

That was my problem....

I just copy and past the golang generated code of postman... and that was the "biggest" difference....

Thanks mr. Postman...

Upvotes: 1

Related Questions