【问题标题】:Grails rest plugin not encoding ampersandGrails rest插件不编码&符号
【发布时间】:2013-07-16 20:29:32
【问题描述】:

我正在使用Grails rest plugin,但在包含与符号的参数方面存在问题。这是我的查询示例:

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)这是一个错误吗?

【问题讨论】:

    标签: rest grails


    【解决方案1】:

    从 0.7 版开始,其余插件使用的 HTTPBuilder 版本在编码(和解码)& 字符时存在问题。

    有一个JIRA Issue 与建议的解决方法(将 HTTPBuilder 升级到 >= 0.5.2)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-25
      • 1970-01-01
      • 2015-03-10
      • 1970-01-01
      • 2016-05-24
      • 2016-01-01
      • 2014-03-13
      • 1970-01-01
      相关资源
      最近更新 更多