Why golang http response shows only half of the message

I did the absolutely same request on golang and node js
and golang’s response much shorten than node’s
here’s my go code

url := "https://qawe.ua/secure/rest/example/pay/12/500000"
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
req.SetBasicAuth(username, passwd)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
req.Header.Set("Token", token)
resp, err := client.Do(req)
if err != nil {
	log.Fatal(err)
}

and my response 

2019/03/24 23:41:23 &{200 OK 200 HTTP/1.1 1 1 map[Expires:[Thu, 01 Jan 1970 00:00:00 GMT] 
Server:[nginx/1.14.2] Date:[Sun, 24 Mar 2019 17:41:23 GMT] Content-Type: 
[application/json;charset=utf-8] Content-Length:[206] X-Powered-By:[Servlet/3.1 JSP/2.3 (GlassFish  
Server Open Source Edition  5.0.1  Java/Oracle Corporation/1.8)] Cache-Control:[no-cache, no- 
store, must-revalidate] Connection:[keep-alive] Pragma:[no-cache] Set-Cookie: 
[JSESSIONID=0caf0170e89cf5cb716c80739dbf; Path=/secure; Secure; HttpOnly] Access-Control- 
Allow-Origin:[*]] 0xc00005e100 206 [] false false map[] 0xc0000f8000 0xc0000c3130}

and in node js returns much much more information

Hi. Maybe the call in node showed the body also. Here you must read it explicitly. But hard to tell when we don’t see what was returned in node.

Omg, thank you, I did not know that we should explicitly read the body of the response, Yeah node JS returns header, body, etc. at once

Is there a better way to work with response body than creating struct and decoding json into it?

Hi. Depends on what you want to do with it. You can unmarshall it into a map of interface{} but then you have to convert fields to the correct type before reading them. I use https://mholt.github.io/json-to-go/ which creates the structs more or less automatically from json.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.