Home > Article > Backend Development > How to Process Plain Text HTTP GET Responses in Golang?
Processing Plain Text HTTP GET Responses in Golang
When sending HTTP GET requests that return plain text responses, capturing the text can be a stumbling block. Here's a definitive guide on how to retrieve the plain text in Golang:
package main import ( "fmt" "io/ioutil" "log" "net/http" ) func main() { url := "http://country.io/capital.json" response, err := http.Get(url) if err != nil { log.Fatal(err) } defer response.Body.Close() responseData, err := ioutil.ReadAll(response.Body) if err != nil { log.Fatal(err) } responseString := string(responseData) fmt.Println(responseString) }
要点:
By following these steps, you can efficiently process plain text HTTP GET responses in Golang, enabling you to further work with the textual data as needed in your application.
The above is the detailed content of How to Process Plain Text HTTP GET Responses in Golang?. For more information, please follow other related articles on the PHP Chinese website!