我在我的应用程序中发送HTTP GET请求
当我使用http.Get(URL)
发送请求时,就像下面的代码一样,我得到200作为HTTP状态代码:
resp, err := http.Get("https://www.google.co.in/")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprintf(w, "HTTP GET returned status %v", resp.Status)
但如果我使用http.NewRequest()
和http.Client
就像下面的代码一样,我会收到502 Bad Gateway nginx
错误
req, err := http.NewRequest("GET", "https://www.google.co.in/", nil)
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)
我检查了堆栈驱动程序日志nginx.error
我看到以下错误
[error] 32#32: *6597 upstream prematurely closed connection while
reading response header from upstream, client: $client_ip, server: ,
request: "GET /check HTTP/1.1", upstream:
"http://172.17.0.1:8080/check", host: "XXX.appspot.com"
我是App Engine的新手,而且我对Nginx知之甚少。