最佳答案
您可以使用 path.Join构建网址。您可能还需要 pathEscape从外部接收的路径参数,以便它们可以安全地放置在路径中。
url1 := path.Join("http://myhost.com/v1/sellers", url.PathEscape(id), "whatever")
req, err := http.NewRequest(http.MethodPost, url1, body)
if err != nil {
return err
}
关于http - 如何使用 golang http 客户端在 url 中正确设置路径参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43826412/