Golang http sends user:passwd information, username password information

Go http sends user:passwd information, username password information

//curl -u

url := "www.aaa.com"
userName := "test"
password := "123"

func SendAuthInfo(url string, userName string, password string) {
    client := &http.Client{}
    req, err := http.NewRequest("GET", url, nil)
    req.SetBasicAuth(userName, password)
    if err != nil {
        return
    }

    resp, err := client.Do(req)
    if err != nil {
         return
    }

    content, err := ioutil.ReadAll(resp.Body)
    if err != nil {
         return
    }
}

SendAuthInfo(url, userName, password)

Comments

Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example