青衣 发表于 2021-7-6 11:02:23

Golang http.MethodGet带参数(GET请求)

  q.Add(“page_size”,“1000”)就是携带的参数,将拼接在url后面发起请求,注意是字符串类型。
import "net/http"
// 获取“项目/仓库”下的所有Artifact
    req, _ := http.NewRequest(http.MethodGet,
      fmt.Sprintf("%s/api/%s/projects/%s/repositories/%s/artifacts",
            url, version.Version, projname, reponame), nil)
    req.SetBasicAuth(username, password)
    q := req.URL.Query()
    q.Add("page_size","1000")
    req.URL.RawQuery = q.Encode()
    fmt.Println(req.URL.String())
    resp, _ = http.DefaultClient.Do(req)
    defer resp.Body.Close()
  

  
页: [1]
查看完整版本: Golang http.MethodGet带参数(GET请求)