when i hit an api i get response with the following code. but i am not getting the header values and status code in postman . how can i get all the values . i.e headers and status code .
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
bodynew, _ := ioutil.ReadAll(resp.Body)
fmt.Fprintf(w, “%s”, bodynewPreformatted text)
Perhaps you can improve your code a bit by also checking for the possible error that http.DefaultClient.Do() returns.
For example:
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatalf("Failed to get API resource: %s", err)
} else if resp.StatusCode >= 400 {
log.Fatalf("API errored. Code: %d", resp.StatusCode)
}
defer resp.Body.Close()
Then you better know what caused the error: failure to get an API response or succeeding to contact the online resource, but getting an error code in returns.