Skip to content

Golang: Get HTTP Response as a String

When you read a response it is in []byte format but you can convert it to string simply by using string() function:


Use this snippet and use it as a simple template for your work:

package main

import (

func main() {
	url := ""

	resp, err := http.Get(url)
	if err != nil {
		log.Fatalf("failed to get: %s", err)

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatalf("failed to read body: %s", err)

	myBodyString := string(body)


Leave a Reply

Your email address will not be published. Required fields are marked *