O
O
onlinejunior2020-05-22 10:57:43
go
onlinejunior, 2020-05-22 10:57:43

How to read the answer?

I'm using http.PostForm .

Trying to read the response without:

read, err := ioutil.ReadAll(response.Body)
  if err != nil {
    log.Printf("Error ReadAll %#v\n", err)
  }


I try to read:

raw, _ := gzip.NewReader(response.Body)
 
dec := json.NewDecoder(raw) или  json.NewDecoder(response.Body)

var v ErrorRes
  if err := dec.Decode(&v); err != nil {

  }


gzip - getting error
json.NewDecoder(response.Body) - empty response

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Papa, 2020-05-23
Stifflera @PapaStifflera

Because http.Response.Body can only be read once. Next, you need to use the read result obtained in the previous step. If, after reading, you need to save the Body value, then you need to manually recreate it. An example can be found here: https://stackoverflow.com/questions/43021058/golan...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question