Answers for "golang http.post basic auth"

0

golang http.post basic auth

func NewFoo(name string) string {
    client := &http.Client{}
    URL := HOST + "foo/"
    v := url.Values{}
    v.Set("name", name)
    //pass the values to the request's body
    req, err := http.NewRequest("POST", URL, strings.NewReader(v.Encode()))
    req.SetBasicAuth(EMAIL, PASSWORD)
    resp, err := client.Do(req)
    if err != nil {
        log.Fatal(err)
    }
    bodyText, err := ioutil.ReadAll(resp.Body)
    s := string(bodyText)
    return s
}
Posted by: Guest on May-18-2021

Browse Popular Code Answers by Language