Un semplice di client di servizio Restful con GO
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
func main() {
client := http.Client{}
req, err := http.NewRequest("GET", "http://xxxxxxxxxxxxxxxxx/api/v1/authentication/", nil)
if err != nil {
//Handle Error
}
req.Header = http.Header{
"Host": []string{"http://xxxxxxxxxxxxxxxxxx/api/v1/authentication/"},
"api-key": []string{"axxxxxxxxxxxx"},
"api-version": []string{"v1"},
"device-language": []string{"it"},
"id-user-session": []string{"guest"},
"Accept": []string{"application/json"},
"Authorization": []string{"Basic Z2lvxxxxxxxxxxxxxxsaQ=="},
}
res, err := client.Do(req)
if err != nil {
fmt.Errorf("got error")
} else {
//fmt.Println("--------------------------")
//fmt.Println(res)
}
defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatalln(err)
}
fmt.Println(string(b))
}
Nessun commento:
Posta un commento