我正在尝试从接受有效负载的 POST 端点检索响应。
对于curl要求:
curl --request POST \
--url https://api.io/v1/oauth/token \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"userToken": "myemail@domain.com:MyUserProfileToken"
}'
我可以这样做:
func GetJWT() string {
endpoint := "https://api.io/v1/oauth/token"
payload := strings.NewReader(`{
"userToken":"myemail@domain.com:MyUserProfileToken"
}`)
req, _ := http.NewRequest("POST", endpoint, payload)
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
return string(body)
}
和
payload := strings.NewReader("{\n \"userToken\": \"myemail@domain.com:MyUserProfileToken\"\n}")
但是,当我尝试为电子邮件和令牌传递字符串指针,并声明有效负载时
func GetJWT(userEmail, userToken *string) string {
endpoint := "https://api.io/v1/oauth/token"
payload := strings.NewReader("{\n \"userToken\": \*userEmail\":\"\*userToken\n}")
req, _ := http.NewRequest("POST", endpoint, payload)
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
return string(body)
}
未知转义返回错误(负载声明的第 53 列)。
我如何转义字符串指针以便连接userEmail、“:” 和userToken
拉丁的传说
相关分类