最近因調用gitlab API,在生成某些字符串的時候直接請求 gitlab API 失敗, url以下:nginx
keysURL := "http://192.168.1.212:10080/api/v3/user/keys?id=" + strconv.Itoa(model.Id) + "&private_token=" + privateToken + "&key=" + pub + "&title=gitclone"
查找問題發現是字符串編碼問題,利用git
url.QueryEscape()
keysURL := "http://192.168.1.212:10080/api/v3/user/keys?id=" + strconv.Itoa(model.Id) + "&private_token=" + privateToken + "&key=" + url.QueryEscape(pub) + "&title=gitclone"
解決了問題。api