例如,如果我打电话给:
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't find property with name {:%28id,first-name,last-name%29} in resource of type {Person}</message> </error>
你怎么处理呢? 目前,我无法更改代码,因为我的语言(Golang btw)使用standar软件包可以非常正确地对其进行编码。这是我的代码:
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)
除了重写std lib代码以外,您是否有解决此问题的方法?
自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类型文档介绍了如何做到这一点。