Hello friends,

I need to authenticate to a PHP application running on the Apache server. 
Authentication type: Basic. I'm trying this code, but I get the 
unauthorized user.

func ....
username = "****"
    passwd = "*****"
    myurl = "http://aplicacao:8085/";
    client := &http.Client{}
     req, err := http.NewRequest("GET", myurl, nil)
    req.Header.Add("Www-Authenticate", "Basic realm= ")
    req.Header.Add("Authorization", "Restricted")
    req.SetBasicAuth(username, passwd)
    //  req.BasicAuth(
    resp, err := client.Do(req)
    if err != nil {
        log.Println("ERRO: ", err)
    }
    log.Println("RESP: ", resp)
    defer resp.Body.Close()

    bodyText, err := ioutil.ReadAll(resp.Body)
    log.Println("BODY: ", string(bodyText))

I get the error:

2020/07/08 11:58:38 RESP: &{401 Unauthorized 401 HTTP/1.0 1 0 
map[Content-Length:[139] Content-Type:[text/html] Server:[Aplicacao] 
Www-Authenticate:[Basic realm="Aplicacao"]] 0xc000186080 139 [] true false 
map[] 0xc00012c000 <nil>} 2020/07/08 11:58:38 BODY: <html><head><title>401 
Unauthorized</title></head><body><h1>You need a password to access this 
page!</h1><a href="/">Home</a></body></html>

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/24f66d37-75b7-4548-8050-7862a15dcd9bo%40googlegroups.com.

Reply via email to