Skip to content

Instantly share code, notes, and snippets.

@lujiacn
Created November 20, 2015 09:25
Show Gist options
  • Save lujiacn/bd6a4e409560a175c96b to your computer and use it in GitHub Desktop.
Save lujiacn/bd6a4e409560a175c96b to your computer and use it in GitHub Desktop.
go client basic auth
## from https://answers.callfire.com/hc/en-us/articles/205407787-Authentication
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
func main() {
client := &http.Client{}
req, err := http.NewRequest("GET", "https://www.callfire.com/api/1.1/rest/contact", nil)
req.SetBasicAuth("<username>", "<password>")
resp, err := client.Do(req)
if err != nil {
fmt.Printf("Error : %s", err)
}
// Retrieve the body of the response
body, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
log.Fatal(err)
}
// Dump the response
fmt.Printf("%s", body)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment