json - Go: How do I turn response body into request body? -
i have handler makes request elasticsearch. cat json response request:
resp, err := http.get(geturl) defer resp.body.close() bodystring := "" if resp.statuscode == 200{ bodybytes, err := ioutil.readall(resp.body) checkforerror(err) bodystring = string(bodybytes) fmt.fprintf(w, bodystring) }
how turn bodystring
can pass http.post of sort:
http.post("https://httpbin.org/post", "application/json; charset=utf-8", jsondata)
i not sure trying achive, may help.
bodybytes, err := ioutil.readall(resp.body) reader := bytes.newreader(bodybytes) http.post("https://httpbin.org/post", "application/json; charset=utf-8", reader) //or can directly //http.post("https://httpbin.org/post", "application/json; charset=utf-8", resp.body)
Comments
Post a Comment