1

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

  • If i make a request with x-token header on Postman to the requested API i get the right header.
  • If i change the request address on the API that makes requests, e.g httpbin, i get the right header too....
2
  • 1
    what is the output of fmt.Println(c.Request.Header) ? Commented Oct 11, 2016 at 5:38
  • @Apin i edited the question! :) Commented Oct 11, 2016 at 10:30

1 Answer 1

1

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...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.