1 回答

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超8個(gè)贊
這是一個(gè)用于http.NewRequest
添加標(biāo)頭的工作解決方案。
func handler(w http.ResponseWriter, r *http.Request) {
? ? ctx := appengine.NewContext(r)
? ? client := urlfetch.Client(ctx)
? ? req, err := http.NewRequest("GET", "https://www.google.com/", nil)
? ? req.Header.Add("CUSTOM-HEADER", "VALUE")
? ? if err != nil {
? ? ? ? ? ? http.Error(w, err.Error(), http.StatusInternalServerError)
? ? ? ? ? ? return
? ? }
? ? resp, err := client.Do(req)
? ? if err != nil {
? ? ? ? ? ? http.Error(w, err.Error(), http.StatusInternalServerError)
? ? ? ? ? ? return
? ? }
? ? fmt.Fprintf(w, "HTTP GET returned status %v", resp.Status)
}
- 1 回答
- 0 關(guān)注
- 137 瀏覽
添加回答
舉報(bào)