golang 访问 BasicAuth 认证的 http
作者:互联网
import (
"net/http"
"strings"
urlpkg "net/url"
)
url := "http://jenkins/job/test/buildWithParameters"
data := urlpkg.Values{}
data.Add("SERVER_NAME", "测试服")
data.Add("SERVER_URI", "refs/heads/master")
data.Add("CONFIG_URI", "refs/heads/master")
req, err := http.NewRequest("POST", url, strings.NewReader(data.Encode()))
if err != nil {
panic(err.Error())
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.SetBasicAuth("wameidemao", "1151edd79316129baea8911ce078908130")
resp, err := http.DefaultClient.Do(req)
标签:http,err,url,req,BasicAuth,golang,Add,data 来源: https://blog.csdn.net/qq_32907195/article/details/116756601