2016-10-11 85 views
1

我正在建造2 apis。一個向另一個請求。Golang錯誤的http resquest header

要調用接收請求的api,我們需要傳遞一個X-Token Header。我與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標頭gin這樣的:

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

我不知道爲什麼我的頭與另一個值和沒有到達X-令牌。謝謝!

結果的fmt.Printf("%+v", c.Request.Header)

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

我不知道哪裏是我的X-令牌接受內容類型頭....

重要

  • 如果我向發送郵件x-token Postman上的請求到請求的API,我得到正確的頭文件。
  • 如果我改變,使得請求API,e.g httpbin,我得到正確的頭太上述請求地址....
+1

fmt.Println(c.Request.Header)的輸出是什麼? – Apin

+0

@Apin我編輯了這個問題! :) – tiagopotencia

回答