0

I am sending HTTP GET request in my App

When I send the request using http.Get(URL) just like the following code I get 200 as HTTP status code:

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)

But if I use http.NewRequest() and http.Client just like the following code I get 502 Bad Gateway nginx error

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)

I checked Stackdriver log for nginx.error I see the following 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"

I am new to App Engine and also I have limited knowledge of Nginx.

Gurjit Singh
  • 31
  • 1
  • 4
  • If you look at the [source for `Client.Get`](https://golang.org/src/net/http/client.go?s=12688:12748#L378), you'll see that it is exactly the same as calling `Client.Do`. You have something else going on which you haven't shown here. – JimB Feb 01 '18 at 20:42
  • @JimB There is nothing else going on I know this should work probably this is because of App Engine – Gurjit Singh Feb 02 '18 at 04:42
  • 1
    You haven't shown how you're creating `client`, how is it different from `http.DefaultClient`? How is its Transport configured? – JimB Feb 02 '18 at 13:28

0 Answers0