我正在使用Grails rest 插件,并且遇到包含 & 符号的参数的问题。这是我的查询示例:
def query = [
method: 'artist.getinfo',
artist: 'Matt & Kim',
format: 'json'
]
withRest(uri:'http://ws.audioscrobbler.com/') {
def resp = get(path: '/2.0/', query: query)
}
我认为 get 方法应该自动对查询中的参数进行 URL 编码 - 它正确地将空格转换为“+”。但是,它保留了 & 符号,这是不正确的(它应该被编码为 %26)。
我尝试在调用 get 之前手动编码艺术家姓名,但随后其余插件对百分号进行编码!
我为其余客户端打开了日志记录,因此我可以看到它请求的 URL。起初:http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Matt+&+Kim&format=json
如果我手动编码名称:http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Matt+%2526+Kim&format=json
我需要设置编码类型吗?(last.fm API 指定 UTF-8)这是一个错误吗?