LinkedIn API 调用 url 编码

LinkedIn API call with url encoded

例如,如果我打电话给:

https://api.linkedin.com/v1/people/~:(id,first-name,last-name)

它应该工作正常,但是如果 URL 编码(并且应该是)像这样:

https://api.linkedin.com/v1/people/~:%28id,first-name,last-name%29

我收到此错误消息:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
    <status>404</status>
    <timestamp>1423577265744</timestamp>
    <request-id>6B2UQSA25W</request-id>
    <error-code>0</error-code>
    <message>[invalid.property.name]. Couldn&#39;t find property with name {:%28id,first-name,last-name%29} in resource of type {Person}</message>
</error>

你如何应对?
目前我无法更改代码,因为我的语言(Golang btw)确实使用标准包非常正确地对其进行了编码。这是我的代码:

r, _ := http.NewRequest("GET", "https://api.linkedin.com/v1/people/~:(id,first-name,last-name)", nil)
r.Header.Set("Authorization", "Bearer "+respBody.AccessToken)
resp, err = http.DefaultClient.Do(r)

除了重写标准库代码之外,您是否有解决此问题的方法?

一些自 2013 年以来面临同样问题的人 https://developer.linkedin.com/forum/edit-i-dont-way-uris-look

创建请求后将URL不透明字段设置为路径:

r, err := http.NewRequest("GET", "https://api.linkedin.com", nil)
if err != nil {
  // handle error
}
r.URL.Opaque = "/v1/people/~:(id,first-name,last-name)"
r.Header.Set("Authorization", "Bearer "+respBody.AccessToken)
resp, err = http.DefaultClient.Do(r)

URL type 文档描述了如何执行此操作。