我有一个向 elasticsearch 发出请求的处理程序。我从该请求中得到 json 响应: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)}我如何把它bodyString变成我可以传递给这种 http.Post 的东西:http.Post("https://httpbin.org/post", "application/json; charset=utf-8", jsonData)
1 回答
萧十郎
TA贡献1815条经验 获得超13个赞
我不确定您要达到什么目标,但可能会有所帮助。
bodyBytes, err := ioutil.ReadAll(resp.Body)
reader := bytes.NewReader(bodyBytes)
http.Post("https://httpbin.org/post", "application/json; charset=utf-8", reader)
//or you can do it directly
//http.Post("https://httpbin.org/post", "application/json; charset=utf-8", resp.Body)
- 1 回答
- 0 关注
- 229 浏览
添加回答
举报
0/150
提交
取消
