Zugriff auf HTTP-Antwort als string in Gehen

Möchte ich Parsen der Antwort eines web-Anfrage, aber ich bin immer Probleme beim Zugriff auf als string.

func main() {
    resp, err := http.Get("http://google.hu/")
    if err != nil {
        //handle error
    }
    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)

    ioutil.WriteFile("dump", body, 0600)

    for i:= 0; i < len(body); i++ {
        fmt.Println( body[i] ) //This logs uint8 and prints numbers
    }

    fmt.Println( reflect.TypeOf(body) )
    fmt.Println("done")
}

Wie kann ich auf die Antwort als string? ioutil.WriteFile schreibt richtig, die Reaktion auf eine Datei.

Hab ich schon überprüft der Paket-Hinweis, aber es ist nicht wirklich hilfreich.

InformationsquelleAutor der Frage Tibor Szasz | 2016-07-30

Schreibe einen Kommentar